public static void checkListInsertAtMiddleSpeed(int quantity, int newQuantity) { int mid = quantity / 2; LinkedList <Temp> testLL = createLinkedList(quantity); Console.WriteLine("Procesing (with LinkedList). Please wait... \n"); stopWatchLL.Restart(); var curNode = testLL.First; for (var k = 0; k < mid; k++) { curNode = curNode.Next; } for (int i = 0; i < newQuantity; i++) { var a = new Temp(i, i, i, i); testLL.AddAfter(curNode, a); } stopWatchLL.Stop(); tsLL = stopWatchLL.Elapsed; string elapsedTimeLL = String.Format("{0:00}.{1:000}", tsLL.Seconds, tsLL.Milliseconds); LinkedListUtils.printReportLL(elapsedTimeLL); }
public static void checkListDeleteFirstSpeed(int quantity) { LinkedList <Temp> testLL = createLinkedList(quantity); Console.WriteLine("Procesing (with LinkedList). Please wait... \n"); stopWatchLL.Restart(); testLL.RemoveFirst(); stopWatchLL.Stop(); tsLL = stopWatchLL.Elapsed; string elapsedTimeLL = String.Format("{0:00}.{1:000}", tsLL.Seconds, tsLL.Milliseconds); LinkedListUtils.printReportLL(elapsedTimeLL); }
public static void checkEmptyListAddSpeed(int quantity) { LinkedList <Temp> testLL = new LinkedList <Temp>(); Console.WriteLine("Procesing (with LinkedList). Please wait... \n"); stopWatchLL.Restart(); for (int i = 0; i < quantity; i++) { var a = new Temp(i, i, i, i); testLL.AddLast(a); } stopWatchLL.Stop(); tsLL = stopWatchLL.Elapsed; string elapsedTimeLL = String.Format("{0:00}.{1:000}", tsLL.Seconds, tsLL.Milliseconds); LinkedListUtils.printReportLL(elapsedTimeLL); }
public static void listFindObjectSpeed(int quantity, int value) { LinkedList <Temp> testLL = createLinkedList(quantity); Console.WriteLine("Procesing (with LinkedList). Please wait... \n"); stopWatchLL.Restart(); foreach (Temp t in testLL) { if (t.i1 == value) { var index = testLL.Find(t); break; } } stopWatchLL.Stop(); tsLL = stopWatchLL.Elapsed; string elapsedTimeLL = String.Format("{0:00}.{1:000}", tsLL.Seconds, tsLL.Milliseconds); LinkedListUtils.printReportLL(elapsedTimeLL); }
static void Main(string[] args) { int quantity; int newQuantity; int value; bool loop = true; while (loop) { Utils.printMenu(); string menuSelector = Console.ReadLine(); Console.Write("\n"); switch (menuSelector) { case "1": quantity = Utils.setNewQuantity(); if (quantity != 0) { ArrayListUtils.checkEmptyListAddSpeed(quantity); LinkedListUtils.checkEmptyListAddSpeed(quantity); } break; case "2": quantity = Utils.setQuantity(); newQuantity = Utils.setNewQuantity(); if (quantity != 0 && newQuantity != 0) { ArrayListUtils.checkListInsertAtMiddleSpeed(quantity, newQuantity); LinkedListUtils.checkListInsertAtMiddleSpeed(quantity, newQuantity); } break; case "3": quantity = Utils.setQuantity(); newQuantity = Utils.setNewQuantity(); if (quantity != 0 && newQuantity != 0) { ArrayListUtils.checkListInsertAtBeginningSpeed(quantity, newQuantity); LinkedListUtils.checkListInsertAtBeginningSpeed(quantity, newQuantity); } break; case "4": quantity = Utils.setQuantity(); value = Utils.setValue(); if (quantity != 0 && value != 0) { ArrayListUtils.listFindObjectSpeed(quantity, value); LinkedListUtils.listFindObjectSpeed(quantity, value); } break; case "5": quantity = Utils.setQuantity(); if (quantity != 0) { ArrayListUtils.checkListDeleteLastSpeed(quantity); LinkedListUtils.checkListDeleteLastSpeed(quantity); } break; case "6": quantity = Utils.setQuantity(); if (quantity != 0) { ArrayListUtils.checkListDeleteMidSpeed(quantity); LinkedListUtils.checkListDeleteMidSpeed(quantity); } break; case "7": quantity = Utils.setQuantity(); if (quantity != 0) { ArrayListUtils.checkListDeleteFirstSpeed(quantity); LinkedListUtils.checkListDeleteFirstSpeed(quantity); } break; case "0": loop = false; break; default: Console.Write("Illegal input"); break; } } }