static void Main(string[] args)
        {
            //List1
            List list = new List();

            list.InsertAtFront("10");
            list.InsertAtFront("50");
            list.InsertAtFront("30");
            list.InsertAtBack("45");
            list.InsertAtFront("80");
            list.InsertAtFront("20");
            list.InsertAtBack("82");

            //List2
            List list2 = new List();

            list2.InsertAtFront("52");
            list2.InsertAtFront("58");
            list2.InsertAtFront("38");
            list2.InsertAtBack("88");
            list2.InsertAtFront("85");
            list2.InsertAtFront("21");

            //Displaying Unsorted List
            Console.BackgroundColor = ConsoleColor.DarkGray;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\nUnsorted Lists: ");
            Console.Write("List1: ");
            list.Display();
            Console.Write("\nList2: ");
            list2.Display();

            //Sorting List
            Console.BackgroundColor = ConsoleColor.Magenta;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\n\nSorted Lists:");
            List SortedList1 = list.Sort();
            List SortedList2 = list2.Sort();

            Console.Write("List1: ");
            list.Display();
            Console.Write("\nList2: ");
            list2.Display();

            //Merging list
            Console.BackgroundColor = ConsoleColor.Red;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\n\nMerged List:");
            List mergedList = SortedList1.Merge(SortedList2);

            mergedList.Display();
            Console.ReadKey();
        }
Example #2
0
    public static void Main( string[] args )
    {
        List list = new List(); // create List container

          // create data to store in List
          bool aBoolean = true;
          char aCharacter = '$';
          int anInteger = 34567;
          string aString = "hello";

          // use List insert methods
          list.InsertAtFront( aBoolean );
          list.Display();
          list.InsertAtFront( aCharacter );
          list.Display();
          list.InsertAtBack( anInteger );
          list.Display();
          list.InsertAtBack( aString );
          list.Display();

          // use List remove methods
          object removedObject;

          // remove data from list and display after each removal
          try
          {
         removedObject = list.RemoveFromFront();
         Console.WriteLine( removedObject + " removed" );
         list.Display();

         removedObject = list.RemoveFromFront();
         Console.WriteLine( removedObject + " removed" );
         list.Display();

         removedObject = list.RemoveFromBack();
         Console.WriteLine( removedObject + " removed" );
         list.Display();

         removedObject = list.RemoveFromBack();
         Console.WriteLine( removedObject + " removed" );
         list.Display();
          } // end try
          catch ( EmptyListException emptyListException )
          {
         Console.Error.WriteLine( "\n" + emptyListException );
          } // end catch
    }
Example #3
0
 static void Main(string[] args)
 {
     LinkedListLibrary.List list = new LinkedListLibrary.List();
     Console.WriteLine("A list");
     list.InsertAtBack(2.4);
     list.InsertAtBack(4.5);
     list.InsertAtBack(2.7);
     list.InsertAtBack(1.9);
     list.InsertAtBack(7.2);
     list.Display();
     Console.WriteLine("Search for 7.3... It exists?");
     Console.WriteLine(list.Search(7.3) > 0?"Yes, it does!": "No, it does not!");
     Console.WriteLine("Search for 7.2... It exists?");
     Console.WriteLine(list.Search(7.2) > 0 ? "Yes, it does!" : "No, it does not!");
     Console.WriteLine("There are " + list.Count() + " in the List!");
     Console.WriteLine("The SUM of all elements in the list is: " + MyToString.ToString(list.Sum()));
 }