/////////////////////////////////////////////////////////////////////// // Client.cpp - Strategy Example Code - Sorting // // Ver: 1.0 // // Language: Visual C++ 2010 // // Platform: Dell Dimension T7400, Win 7, Pro // // Author: Jim Fawcett, CSE776 - Design Patterns, Summer 2010 // // Source: Lei Zhang, lzhang17@syr.edu // /////////////////////////////////////////////////////////////////////// /* Purpose: -------- Illustrates application of Strategy Pattern to measuring, and potentially using different sorting strategies. Maintenance History: -------------------- Ver 1.1 : 27 Jun 2010 - cosmetic modifications Ver 1.0 : 02 Jul 2007 - first release */ #include "Record.h" #include #include using namespace std; int main() { cout << "\n Pattern: Strategy Example Code" << "\n " << string(50, '=') << endl; cout << "\n Strategy initially configured as InsertionSort"<< "\n " << string(35, '=') << endl; Record rec(new InsertionSort()); rec.recordGenerator(); DWORD StartTime = GetTickCount(); rec.doSorting(); rec.display(); DWORD EndTime = GetTickCount(); cout << " Ticks for InsertionSort: " << EndTime - StartTime << endl; cout << "\n Set strategy to QuickSort"<< "\n " << string(35, '=') << endl; rec.setSortS(new QuickSort()); rec.recordGenerator(); StartTime = GetTickCount(); rec.doSorting(); rec.display(); EndTime = GetTickCount(); cout << " Ticks for QuickSort: " << EndTime - StartTime << endl; cout << "\n Set strategy to MergeSort" << "\n " << string(35, '=') << endl; rec.setSortS(new MergeSort()); rec.recordGenerator(); StartTime = GetTickCount(); rec.doSorting(); rec.display(); EndTime = GetTickCount(); cout << " Ticks for MergeSort: "<