public void UndoSorting(List <TShirt> unsorted, TShirtList sorted) { for (int i = 0; i < 100; i++) { sorted.TShirts[i] = unsorted[i]; } }
public void SortBySizeAscending(List <TShirt> randomTShirtsUnsorted, TShirtList tShirtList) { Stopwatch stopWatch = new Stopwatch(); TimeSpan BubbleSortTimeSpan, QuickSortTimeSpan, BucketSortTimeSpan; Console.WriteLine("The T-Shirts list unsorted:"); PrintList(tShirtList.TShirts); Console.WriteLine(); tShirtList.SetSortStrategy(new BubbleSortStrategy()); stopWatch.Start(); tShirtList.SortBySizeAscending(); stopWatch.Stop(); BubbleSortTimeSpan = stopWatch.Elapsed; Console.WriteLine("T-Shirts list sorted ascending by size using Bubblesort:"); PrintList(tShirtList.TShirts); Console.WriteLine(); UndoSorting(randomTShirtsUnsorted, tShirtList); tShirtList.SetSortStrategy(new QuickSortStrategy()); stopWatch.Restart(); tShirtList.SortBySizeAscending(); stopWatch.Stop(); QuickSortTimeSpan = stopWatch.Elapsed; Console.WriteLine("T-Shirts list sorted ascending by size using Quicksort:"); PrintList(tShirtList.TShirts); Console.WriteLine(); UndoSorting(randomTShirtsUnsorted, tShirtList); tShirtList.SetSortStrategy(new BucketSortStrategy()); stopWatch.Restart(); tShirtList.SortBySizeAscending(); stopWatch.Stop(); BucketSortTimeSpan = stopWatch.Elapsed; Console.WriteLine("T-Shirts list sorted ascending by size using Bucketsort:"); PrintList(tShirtList.TShirts); Console.WriteLine(); PrintTimingResults(BubbleSortTimeSpan, QuickSortTimeSpan, BucketSortTimeSpan); }
static void Main(string[] args) { List <TShirt> randomTShirtsUnsorted = new List <TShirt>(); TShirt tShirt; SortManager sortManager = new SortManager(); TShirtList tShirtList = new TShirtList(); tShirtList.TShirts = new List <TShirt>(); for (int i = 0; i < 100; i++) { tShirt = new TShirt(RandomString(10), (Color)random.Next(0, 7), (Size)random.Next(0, 7), (Fabric)random.Next(0, 7)); randomTShirtsUnsorted.Add(tShirt); tShirtList.TShirts.Add(tShirt); } Console.WriteLine("Press any key to proceed to sorting ascending by size."); Console.ReadKey(); sortManager.SortBySizeAscending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting descending by size."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortBySizeDescending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting ascending by color."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortByColorAscending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting descending by color."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortByColorDescending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting ascending by fabric."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortByFabricAscending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting descending by fabric."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortByFabricDescending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting ascending by size then color then fabric."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortBySizeThenColorThenFabricAscending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to proceed to sorting descending by size then color then fabric."); Console.ReadKey(); sortManager.UndoSorting(randomTShirtsUnsorted, tShirtList); sortManager.SortBySizeThenColorThenFabricDescending(randomTShirtsUnsorted, tShirtList); Console.WriteLine(); Console.WriteLine("Press any key to exit program."); Console.ReadKey(); }