// 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( ) { // 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); }