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

C language /python classic algorithm bubble sort

編輯:Python

C Language classic algorithm bubble sort

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

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

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

if (a[j]>a[j+1])
{

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

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

C Language classic algorithm function real bubble sort

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

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

for (int j = 0; j < 10; j++)
{

if (a[j]>a[j+1])
{

int b = a[j+1];
a[j+1] = a[j];
a[j] = b;
}
}
}
}
int main()
{

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

scanf("%d",&b[i]);
}
maopao(b);
for (int i = 0; i < 10; i++)
{

printf("%d",b[i]);
}
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(9):
if list1[b]>list1[b+1]:
c = list1[b]
list1[b] = list1[b+1]
list1[b+1] =c
for a in list1:
print(a)

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