首页 > 其他 > 详细

从后往前冒泡

时间:2019-04-18 19:13:13      阅读:165      评论:0      收藏:0      [点我收藏+]
//
//  main.cpp
//  test
//  随便写的
//  Created by mac on 2019/4/18.
//  Copyright ? 2019年 mac. All rights reserved.
//

#include <iostream>
#include <list>
#include <vector>
#include <string>
using namespace std;

void bubble(int*a,int n)//冒泡升序
{int j;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
    
                if(a[j]<a[j-1])
                {
                    int temp=a[j];
                    a[j]=a[j-1];
                    a[j-1]=temp;
                    
                }
            
        }
    
}
}
int main(int argc, const char * argv[]) {
    // insert code here...
    list<string> a={"aa","bb","cc"};
    list<string>::iterator it1=a.begin();
    list<string>::reverse_iterator it2=a.rbegin();
    list<string>::const_iterator it3=a.cbegin();
    list<string>::const_reverse_iterator it4 = a.crbegin();
    
//    int arr[5]={0x11};
//    cout << 10%-3;
    
    int array[10]={1,2,3,23,21,13,11,-9,7,10};
    bubble(array, 10);
    for (int i=0;i<10; i++) {
        cout<<array[i]<<" ";
        
    }
    cout<<endl;
    return 0;
}

运行结果

-9 1 2 3 7 10 11 13 21 23 
Program ended with exit code: 0

从后往前冒泡

原文:https://www.cnblogs.com/overlows/p/10731558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!