排序算法之冒泡排序

2022/4/14 14:13:03

本文主要是介绍排序算法之冒泡排序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int data[]={1,5,3,6,4,2};
 6     /*increase*/
 7     /*
 8     int i=0;    
 9     for(;i<6-1;i++){
10         int j=0;
11         for(;j<6-1-i;j++){
12             if(data[j]>data[j+1]){
13                 int temp = data[j];
14                 data[j] = data[j+1];
15                 data[j+1] = temp;
16             }
17             
18         }
19     }*/
20     /*decrease*/
21     int i=0;    
22     for(;i<6-1;i++){
23         int j=0;
24         for(;j<6-1-i;j++){
25             if(data[j]<data[j+1]){
26                 int temp = data[j];
27                 data[j] = data[j+1];
28                 data[j+1] = temp;
29             }
30             
31         }
32     }
33 
34     for(i=0;i<6;i++){
35         printf("%d",data[i]);
36     }
37 }

 



这篇关于排序算法之冒泡排序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程