/******************************************************************************************** bubble.cpp Jim Millard for CO311 Bubble sort algorithm ********************************************************************************************/ #include <iostream> #include <string> using namespace std; #include "sorttool.h" void BubbleSort(int [], const int size, const int used); void main() { const int MaxSize = 1000; int Array[MaxSize]; int toSort; cout << "How many numbers to sort (up to " << MaxSize << "): "; cin >> toSort; FillWithRand(Array, MaxSize, toSort); //setup the array with X numbers cout << "Unsorted:" << endl; ParseAndPrint(Array, MaxSize, toSort); //show the unsorted array BubbleSort(Array, MaxSize, toSort); //sort the first X elements of the array cout << "Sorted:" << endl; ParseAndPrint(Array, MaxSize, toSort); //show the (hopefully) sorted array } void BubbleSort(int Array[], const int maxsize, const int count) { bool DoneSorting = false; while (!DoneSorting) { DoneSorting = true; for (int current = 0; (current < count-1) && (current < maxsize-1); current++) if (Array[current] > Array[current+1]) { DoneSorting = false; Swap(Array[current],Array[current+1]); } } return; }