#include<iostream> int main() { int a[10]; for(int i = 0; i<10; i++) { a[i] = 10 - i; } std::cout<<"The initial sequece:"<<std::endl; for(int i = 0; i<10; i++) { std::cout<<" "<<a[i]; } std::cout<<std::endl; for(int i = 1; i<10; i++) { int k1 = a[i]; for(int j = i-1; j>=0; j--) { int k2 = a[j]; if(k1<k2) { a[j+1] = k2; a[j] = k1; } } } std::cout<<"The final sequece:"<<std::endl; for(int i = 0; i<10; i++) std::cout<<" "<<a[i]; return 0; }
原文:http://www.cnblogs.com/xiatoex/p/5225022.html