从后往前冒泡
//
// 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
未经本人准许,禁止转载.