码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2017-01-03 07:29:00      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:char   div   auth   strong   amp   log   author   getch   冒泡   

 

 

 1 /*  Version:0.1  
 2     Date:2017年1月2日  
 3     Author:
 4     function:冒泡排序
 5 */
 6 
 7 #include <stdio.h>  
 8 #include <stdlib.h>   
 9 
10 int main()  
11 {
12     int a[5], i, j, temp;
13 
14     for(i=0; i<5; i++)
15         scanf("%d", &a[i]);
16     
17     for(i=0; i<5; i++)
18            for(j=i+1; j<5; j++)
19                if(a[i] > a[j])
20                 {
21                     temp = a[i];
22                     a[i] = a[j];
23                     a[j] = temp;
24                 }
25   
26     for(i=0; i<5; i++)
27         printf("%d ", a[i]);
28         
29     getchar();getchar();
30     return 0;  
31 }

时间复杂度

O(N2)

冒泡排序

标签:char   div   auth   strong   amp   log   author   getch   冒泡   

原文地址:http://www.cnblogs.com/lightyear-one/p/6243583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!