Created
May 17, 2018 07:31
-
-
Save corerman/3dae0e7e00f33b2b3ad100cad1d23565 to your computer and use it in GitHub Desktop.
算法: Bubble_Sort.sh 冒泡排序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
int numlist[100],len=0,num=0; | |
while(scanf("%d",&num)!=EOF){ | |
numlist[len]=num; | |
len++; | |
} | |
int tempnum=0; | |
for(int i=0;i<len-1;i++){ | |
for(int i2=0;i2<len-1-i;i2++){ | |
if(numlist[i2]>numlist[i2+1]){ | |
tempnum=numlist[i2]; | |
numlist[i2]=numlist[i2+1]; | |
numlist[i2+1]=tempnum; | |
} | |
} | |
} | |
for (int i = 0; i < len; ++i) { | |
printf("%d ",numlist[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment