Ideas please see
Http://www.cnblogs.com/kkun/archive/2011/11/23/2260280.html
The code is as follows:
1 //171027 bubble sort. cpp: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6 7 using namespacestd;8 9 voidBubble_sort (intA[],intLen//sort in ascending orderTen { One intSwap =0; A for(inti =0; I < len-1; i++)//How many times? - { - for(intj =0; J < len-1-I.; J + +)//how many times per trip? the { - if(A[j] > a[j+1])//If you want to sort in descending order, change here to A[j] < a[j+1] - { -Swap =A[j]; +A[J] = a[j+1]; -a[j+1] =swap; + } A } at } -cout <<"sequence of arrays after sorting:"; - for(inti =0; i < Len; i++) - { -cout << A[i] <<ends; - } incout <<Endl; - } to + intMain () - { the inttest[9] = {1,4,6,9,7,2,8,5,3 }; *cout <<"sequence of arrays before sorting:"; $ for(auto c:test)Panax Notoginsengcout << C <<ends; -cout <<Endl; theBubble_sort (Test,9); + return 0; A}
Bubble sort "Classic sorting algorithm" "Code"