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

屌丝需要逆袭之学习C++和算法------冒泡排序

时间:2014-09-02 15:36:54      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   log   sp   

 1 #include <iostream>
 2 using namespace std;
 3 int BubbleSort(int A[],int n);
 4 int OutPut(int A[],int n);
 5 int main()
 6 {
 7     int A[]={5,1,3,2,4};
 8     BubbleSort(A,5);
 9     OutPut(A,5);
10     return 0;
11 }
12 
13 int BubbleSort(int A[],int n)
14 {
15     for(int i=0;i<n-1;i++)
16     {
17         for(int j=i+1;j<n;j++)
18         {
19             if(A[i]>A[j])
20             {
21                 int temp=A[i];
22                 A[i]=A[j];
23                 A[j]=temp;
24             }
25         }
26     }
27     return 0;
28 }
29 
30 int OutPut(int A[],int n)
31 {
32     for(int i=0;i<n;i++)
33     {
34         cout<<A[i]<<\n;
35     }
36     return 0;
37 }

 

屌丝需要逆袭之学习C++和算法------冒泡排序

标签:style   blog   color   os   io   for   div   log   sp   

原文地址:http://www.cnblogs.com/niuxiaoha/p/3951403.html

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