当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 从后往前冒泡

从后往前冒泡

2019年04月19日  | 移动技术网IT编程  | 我要评论

qq号大全,阿德里安娜,托玛琳能量杯价格

//
//  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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网