主题:[原创]算法知识谱及--002:::冒泡排序!!!
//冒泡排序
#include <stdio.h>
#include <iostream>
int main()
{
int i, j, key;
int sort[10] = {6, 5, 4, 9, 3, 0, 8, 2, 1, 7};
for(i = 0; i < 10; i++){
for(j = 9; j > i; j--){
if(sort[j] < sort[j - 1]){
key = sort[j];
sort[j] = sort[j - 1];
sort[j - 1] = key;
}
}
}
for(i = 0; i< 10; i++){
printf("%d\n",sort[i]);
}
system("pause");
return 0;
}
#include <stdio.h>
#include <iostream>
int main()
{
int i, j, key;
int sort[10] = {6, 5, 4, 9, 3, 0, 8, 2, 1, 7};
for(i = 0; i < 10; i++){
for(j = 9; j > i; j--){
if(sort[j] < sort[j - 1]){
key = sort[j];
sort[j] = sort[j - 1];
sort[j - 1] = key;
}
}
}
for(i = 0; i< 10; i++){
printf("%d\n",sort[i]);
}
system("pause");
return 0;
}