程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

C language /python classic algorithm selection sorting

編輯:Python

C Language classical algorithm selection sorting

#include "stdio.h"
int main()
{

int a[10]={
3,1,2,8,9,5,7,4,0,6};
for (int i = 0; i < 9; i++)
{

for (int j = i+1; j < 10; j++)
{

if (a[i]>a[j])
{

int b = a[i];
a[i] = a[j];
a[j] = b;
}
}
}
for (int i = 0; i < 10; i++)
{

printf("%d",a[i]);
}
return 0;
}

C Language classic algorithm functions to achieve selective sorting

#include "stdio.h"
void xuanzhe(int a[])
{

for (int i = 0; i < 9; i++)
{

for (int j = i+1; j < 10; j++)
{

if (a[i]>a[j])
{

int b = a[i];
a[i]=a[j];
a[j]=b;
}
}
}
for (int i = 0; i < 10; i++)
{

printf("%d",a[i]);
}
}
int main()
{

int a[10];
for (int i = 0; i < 10; i++)
{

scanf("%d",&a[i]);
}
xuanzhe(a);
return 0;
}

Python Implement selection sorting

list1=[3,2,4,1,9,7,0,6,5,8]
for a in range(10):
for b in range(a+1,10):
if list1[a]>list1[b]:
c = list1[a]
list1[a] = list1[b]
list1[b] =c
for a in list1:
print(a)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved