// Gets user input for removing from Linked List static void removeFromList() { Node <string> current = myLinkedList.Head; int nodeCount = 0; string userInput; int userInputConverted; Console.WriteLine("Please choose an item to remove from the list.\n"); while (current != null) { Console.WriteLine("{0}. {1}", nodeCount + 1, current.Value); nodeCount++; current = current.Next; } if (nodeCount != 0) { Console.Write("\n\nPlease choose an item to remove (1-{0}): ", nodeCount); userInput = Console.ReadLine(); try { userInputConverted = Convert.ToInt32(userInput); if (userInputConverted < 1 || userInputConverted > nodeCount + 1) { removeFromList(); } else { myLinkedList.Delete(userInputConverted - 1); } } catch (Exception e) { Console.Clear(); Console.WriteLine("Please enter a number.\n\n{0}", e); pauseScreen(); } } else { Console.Clear(); Console.WriteLine("List is empty."); pauseScreen(); } }
static void Main(string[] args) { Console.WriteLine("Dynamic Array "); var dynamicArray = new DynamicArray(5); dynamicArray.Add(2); dynamicArray.Add(4); dynamicArray.print(); dynamicArray.delete(4); dynamicArray.print(); Console.WriteLine("LinkedList"); var linkedList = new LinkedList(5); linkedList.Add(2); linkedList.Add(4); linkedList.Delete(2); linkedList.print(); Console.WriteLine("Stack "); var stack = new Stack(5); stack.pushValue(2); stack.pushValue(4); stack.popValue(); stack.printValues(); Console.WriteLine("Queue"); var queue = new Queue(5); queue.Enqueue(2); queue.Enqueue(4); queue.Dequeue(); queue.Print(); //MergeSorted array see below Console.WriteLine("Merge Sorted Array "); int[] a = new int[] { 5, 3, 2, 7, 8, 10 }; Sort.MergeSort(a, 0, a.Length - 1); Sort.PrintArray(a); //QuickSorted array see below Console.WriteLine("Quick Sorted Array "); a = new int[] { 5, 3, 2, 7, 8, 10 }; Sort.QuickSort(a, 0, a.Length - 1); Sort.PrintArray(a); }
static void Main(string[] args) { //FIFO Queue queue = new Queue(); Console.WriteLine(queue.IsEmpty()); queue.Add(1); queue.Add(3); queue.Print(); Console.WriteLine(queue.Peek()); queue.Add(5); queue.Add(2); queue.Print(); queue.Remove(); queue.Print(); //LIFO Stack stack = new Stack(); Console.WriteLine(stack.IsEmpty()); stack.Push(1); stack.Push(3); stack.Print(); Console.WriteLine(stack.Peek()); stack.Push(5); stack.Push(2); stack.Print(); stack.Pop(); stack.Print(); Console.ReadKey(); LinkedList linkedList = new LinkedList(1); linkedList.PrindList(); linkedList.Delete(); linkedList.Append(2); linkedList.PrindList(); linkedList.Append(4); linkedList.Append(10); linkedList.PrindList(); linkedList.Delete(); linkedList.PrindList(); linkedList.Clear(); linkedList.PrindList(); linkedList.Append(2); linkedList.Append(4); linkedList.Append(10); linkedList.PrindList(); linkedList.Delete(4); linkedList.PrindList(); linkedList.Clear(); linkedList.PrindList(); linkedList.Append(2); linkedList.Append(4); linkedList.Append(10); linkedList.PrindList(); linkedList.Delete(2); linkedList.PrindList(); linkedList.Clear(); linkedList.PrindList(); linkedList.Append(2); linkedList.Append(4); linkedList.Append(10); linkedList.PrindList(); linkedList.Delete(10); linkedList.PrindList(); Console.ReadKey(); Console.WriteLine("Hello World!"); HeapMin heapMin = new HeapMin(); heapMin.printArray = true; heapMin.Add(3); heapMin.Add(4); heapMin.Add(8); heapMin.Add(1); heapMin.Add(7); heapMin.Add(2); heapMin.Add(5); int min = heapMin.Peek(); Console.WriteLine(min); // should == 1 heapMin.Pool(); heapMin.Pool(); heapMin.Pool(); min = heapMin.Peek(); Console.WriteLine(min); // should == 4 //Console.ReadKey(); //BSTree bSTree = new BSTree(10); //bSTree.Insert(15); //bSTree.Insert(5); //bSTree.PrintInOrder(); //bSTree.Insert(8); //bSTree.PrintInOrder(); //Console.WriteLine(bSTree.Contains(8)); //Console.WriteLine(bSTree.Contains(18)); //Console.ReadKey(); string[] keys = { "the", "a", "there", "answer", "any", "by", "bye", "their" }; string[] output = { "Not present in trie", "Present in trie" }; Trie trie = new Trie(); // Construct trie for (int i = 0; i < keys.Length; i++) { trie.Insert(keys[i]); } // Search for different keys if (trie.Contains("the") == true) { Console.WriteLine("the --- " + output[1]); } else { Console.WriteLine("the --- " + output[0]); } if (trie.Contains("these") == true) { Console.WriteLine("these --- " + output[1]); } else { Console.WriteLine("these --- " + output[0]); } if (trie.Contains("their") == true) { Console.WriteLine("their --- " + output[1]); } else { Console.WriteLine("their --- " + output[0]); } if (trie.Contains("thaw") == true) { Console.WriteLine("thaw --- " + output[1]); } else { Console.WriteLine("thaw --- " + output[0]); } if (trie.Contains("thei") == true) { Console.WriteLine("thei --- " + output[1]); } else { Console.WriteLine("thei --- " + output[0]); } if (trie.Contains("thei", true) == true) { Console.WriteLine("thei (full word search) --- " + output[1]); } else { Console.WriteLine("thei (full word search) --- " + output[0]); } Console.ReadKey(); }