// method to sort LL via Insertion Sort public void InsertionSort( ) { // initialize a new empty LL LL sortedLL = new LL( ); // if this LL is empty or there's only 1 node if (this.count <= 1) { return; } // iterate through this LL while (this.head != null) { // 'take out' first node in unsorted LL Drug currentDrug = this.Pop( ); // insert in sortedLL in order sortedLL.AddInOrder(currentDrug); } this.head = sortedLL.head; this.tail = sortedLL.tail; this.count = sortedLL.count; }
static void Main(string[] args) { LL <int> list = new LL <int>(); for (int i = 0; i < 10; i++) { list.addLast(i); } list.addidx(idx: 2, datum: 99); Console.WriteLine(list.ToString()); Console.WriteLine(list.Reverse()); }
static void Main( ) { // declare new linked lists LL LLofDrugs = new LL( ); LL emptyList = new LL( ); // read file, test your Append method using (FileStream file = File.Open("RXQT1503.txt", FileMode.Open, FileAccess.Read)) using (StreamReader reader = new StreamReader(file)) { for (int i = 0; i < 10; i++) { LLofDrugs.AddInOrder(Drug.ParseFileLine(reader.ReadLine( ))); } } //PrintFormat MyMethod = DetailedString; LLofDrugs.PrintList(DetailedString); WriteLine(); LLofDrugs.PrintList(ShortString); }
public static void Main(string[] args) { Node node1 = new Node("node1"); Node node2 = new Node("node2"); Node node3 = new Node("node3"); Node node4 = new Node("node4"); Node node5 = new Node("node5"); LL LL = new LL(node1); LL.Add(node2); LL.Add(node3); LL.Add(node4); LL.Add(node5); Console.WriteLine("BaseLine"); LL.Print(); Console.WriteLine(""); Console.WriteLine("Append to the end"); Node node6 = new Node("node6"); LL.Append(node6); LL.Print(); Console.WriteLine(""); Console.WriteLine("Add before node3"); Node node7 = new Node("node7"); LL.AddBefore(node7, node3); LL.Print(); Console.WriteLine(""); Console.WriteLine("Add after node4"); Node node8 = new Node("node8"); LL.AddAfter(node8, node4); LL.Print(); Console.WriteLine(LL.Find("node3")); }
static void Main( ) { // declare new linked lists LL LLofDrugs = new LL( ); LL emptyList = new LL( ); // read file, test your Append method using (FileStream file = File.Open("RXQT1503.txt", FileMode.Open, FileAccess.Read)) using (StreamReader reader = new StreamReader(file)) { for (int i = 0; i < 10; i++) { LLofDrugs.Append(Drug.ParseFileLine(reader.ReadLine( ))); } } LLofDrugs.PrintList(); // Test your Pop method // This 'pops' all nodes in the list one-by-one //~ while( LLofDrugs.Pop( ) != null ) //~ { //~ WriteLine(); //~ LLofDrugs.PrintList(); //~ } // Test the different cases for Remove // These should all execute without error when only 10 lines of the file are imported //~ LLofDrugs.Remove("AXIRON"); //~ LLofDrugs.Remove("TRULICITY"); //~ LLofDrugs.Remove("CYMBALTA"); //~ LLofDrugs.Remove("IMAGINATION"); //~ emptyList.Remove("AXIRON"); //~ WriteLine(); //~ LLofDrugs.PrintList(); }