#include using namespace std; void Bubble(int x[], int n) { int hold, j, pass; int switched = true; for (pass = 0; pass < n - 1 && switched == true; pass++) { //outer loop controls the number of passes switched = false; for (j = 0; j < n - pass - 1; j++) { //inner loop controls each individual pass if (x[j] > x[j + 1]) //elements out of order { switched = true; hold = x[j]; x[j] = x[j + 1]; x[j + 1] = hold; } //end if } //end inner for loop } //end outer forloop } //end bubble void insertionsort(int x[], int n) { int j, k, y; /*initially x[0] may be thought of a sorted file of one element. After each repetition of following loop, the elements x[0] through x[k] are in order */ for (k = 1; k < n; k++) { /*insert x[k] into a sorted file*/ y = x[k]; /*move down all elements greater than y*/ for (j = k - 1; j >= 0 && y < x[j]; j++){ x[j + 1] = x[j]; } /*insert y at proper position */ x[j + 1] = y; } } int main() { cout<<"a"; int N[] = { 20000,5000,100,10,10000,50000,1000 }; Bubble(N, 7); for (int i = 0; i < 7; i++) { cout << " " << N[i] << " "; } // int W[] = { 20000,5000,100,10,10000,50000,1000 }; // insertionsort(W, 7); // for (int i = 0; i < 7; i++) { // cout << " " << W[i] << " "; // } }