// // bubble sort algorithm // // Described in Chapter 4 of // Data Structures in C++ using the STL // Published by Addison-Wesley, 1997 // Written by Tim Budd, budd@cs.orst.edu // Oregon State University // # include void bubbleSort (double v[ ], unsigned int n) // exchange the values in the vector v // so they appear in ascending order { // find the largest remaining value // and place into v[i] for (unsigned int i = n - 1; i > 0; i--) { // move large values to the top for (unsigned int j = 0; j < i; j++) { // if out of order if (v[j] > v[j+1]) { // then swap double temp = v[j]; v[j] = v[j + 1]; v[j + 1] = temp; } } } } void main () { double v[100]; int i; for (i = 0; i < 100; i++) v[i] = rand(); bubbleSort(v, 100); for (i = 0; i < 100; i++) cout << v[i] << ' '; cout << "\n"; }