// Test the 'LinkedList.SubList' method. static void Main( ) { // Parameters for reading the drug file. const string path = "RXQT1503.txt"; const FileMode mode = FileMode.Open; const FileAccess access = FileAccess.Read; // Load all drugs into a linked list. LinkedList allDrugs = new LinkedList( ); using (FileStream file = new FileStream(path, mode, access)) using (StreamReader reader = new StreamReader(file)) { while (!reader.EndOfStream) { string line = reader.ReadLine( ); Drug d = Drug.ParseFileLine(line); allDrugs.AddLast(d); } } WriteLine("allDrugs.Count = {0}", allDrugs.Count); // Form a sub-list of Temazipam capsules. LinkedList subDrugs1 = allDrugs.SubList(IsTemazipamCapusule); WriteLine("subDrugs1.Count = {0}", subDrugs1.Count); foreach (Drug d in subDrugs1.ToArray( )) { WriteLine(d); } // Form a sub-list of Lorazepam tablets. LinkedList subDrugs2 = allDrugs.SubList(IsLorazepamTablet); WriteLine("subDrugs2.Count = {0}", subDrugs2.Count); foreach (Drug d in subDrugs2.ToArray( )) { WriteLine(d); } }
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); }
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(); }