/******************************************************************************************** trivial.cpp Jim Millard for CO311 Simplest possible sort that still actually works... ********************************************************************************************/ #include <iostream> #include <string> using namespace std; #include "sorttool.h" void IterativeSort(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 IterativeSort(Array, MaxSize, toSort); //sort the first X elements of the array cout << "Sorted:" << endl; ParseAndPrint(Array, MaxSize, toSort); //show the (hopefully) sorted array } void IterativeSort(int Array[], const int maxsize, const int count) { for (int current = 0; (current < count) && (current < maxsize); current++) for (int target = current; (target < count) && (target < maxsize); target++) if (Array[target] < Array[current]) Swap(Array[target],Array[current]); return; }