static void Main(string[] args) { int choice, data, k, x; DoubleLinkedList list = new DoubleLinkedList(); list.CreateList(); while (true) { Console.WriteLine("1. Display List "); Console.WriteLine("2. Insert in empty list"); Console.WriteLine("3. Insert a node in beginning of the list"); Console.WriteLine("4. Insert a node at the end of the list"); Console.WriteLine("5. Insert a node after a specified node"); Console.WriteLine("6. Insert a node before a specified node"); Console.WriteLine("7. Delete first node"); Console.WriteLine("8. Delete last node"); Console.WriteLine("9. Delete a specified node"); Console.WriteLine("10. Reverse the list"); Console.WriteLine("11. Exit program"); Console.WriteLine("Enter your choice: "); choice = Convert.ToInt32(Console.ReadLine()); if (choice == 11) { break; } switch (choice) { case 1: // Display current list list.DisplayList(); break; case 2: // Insert node to empty list Console.Write("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); list.InsertInEmptyList(data); break; case 3: // Insert node at beginning of list Console.Write("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); list.InsertInBeginning(data); break; case 4: // Insert node at end of list Console.Write("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); list.InsertAtEnd(data); break; case 5: // Insert a node after specifed node Console.Write("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the element before which to insert: "); x = Convert.ToInt32(Console.ReadLine()); list.InsertAfter(data, x); break; case 6: // Insert a node before specified node Console.Write("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the element after which to insert: "); x = Convert.ToInt32(Console.ReadLine()); list.InsertBefore(data, x); break; case 7: // Delete first node list.DeleteFirstNode(); break; case 8: // Delete last node list.DeleteLastNode(); break; case 9: // Delete node with specified data Console.Write("Enter the element to be deleted: "); data = Convert.ToInt32(Console.ReadLine()); list.DeleteNode(data); break; case 10: // Reverse the list list.ReverseList(); break; case 11: // break; } } }
static void Main(string[] args) { int choice, data, x; DoubleLinkedList dlist = new DoubleLinkedList(); dlist.CreateList(); while (true) { Console.WriteLine("1. Display list"); Console.WriteLine("2. Insert in an empty list"); Console.WriteLine("3. Insert a node at the biginning of the list"); Console.WriteLine("4. Insert a node at the end of the list"); Console.WriteLine("5. Insert a node after a specifide node"); Console.WriteLine("6. Insert a node before a specifide node"); Console.WriteLine("7. Delete first node"); Console.WriteLine("8. Delete last node"); Console.WriteLine("9. Delete any node"); Console.WriteLine("10. Reverse the list"); Console.WriteLine("11. Quit"); Console.WriteLine("Enter your choice : "); choice = Convert.ToInt32(Console.ReadLine()); if (choice == 11) { break; } switch (choice) { case 1: dlist.DisplayList(); break; case 2: Console.WriteLine("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); dlist.InsertInEmptyList(data); break; case 3: Console.WriteLine("Enter element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); dlist.InserInBeginning(data); break; case 4: Console.WriteLine("Enter an element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); dlist.InsertAtEnd(data); break; case 5: Console.WriteLine("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter element after which to insert: "); x = Convert.ToInt32(Console.ReadLine()); dlist.InsertAfter(data, x); break; case 6: Console.WriteLine("Enter the element to be inserted: "); data = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the element before wich to insert: "); x = Convert.ToInt32(Console.ReadLine()); dlist.InsertBefor(data, x); break; case 7: dlist.DeleteFirstNode(); break; case 8: dlist.DeleteLastNode(); break; case 9: Console.WriteLine("Enter an element to be deleted:"); data = Convert.ToInt32(Console.ReadLine()); dlist.DeleteNode(data); break; case 10: dlist.ReversList(); break; default: Console.WriteLine("Wrong choice"); Console.WriteLine(); break; } Console.WriteLine(); } Console.WriteLine("Exiting"); }
static void Main(string[] args) { int choice, data, x; DoubleLinkedList list = new DoubleLinkedList(); list.CreateList(); while (true) { Console.WriteLine("1. Display list"); Console.WriteLine("2. Insert in empty list"); Console.WriteLine("3. Insert at the beginning of the list"); Console.WriteLine("4. Insert at the end of the list"); Console.WriteLine("5. Insert node after particular node"); Console.WriteLine("6. Insert node before particular node"); Console.WriteLine("7. Delete first node"); Console.WriteLine("8. Delete last node"); Console.WriteLine("9. Delete particualr node"); Console.WriteLine("10. The list reverse"); Console.WriteLine("11. Exit"); do { Console.WriteLine("Enter your choice: "); }while (!int.TryParse(Console.ReadLine(), out choice)); if (choice == 11) { break; } Console.Clear(); switch (choice) { case 1: list.DisplayList(); break; case 2: do { Console.WriteLine("Insert node: "); }while (!int.TryParse(Console.ReadLine(), out data)); list.InsertInEmptyList(data); break; case 3: do { Console.WriteLine("Insert node: "); }while (!int.TryParse(Console.ReadLine(), out data)); list.InsertInBeginning(data); break; case 4: do { Console.WriteLine("Insert node: "); }while (!int.TryParse(Console.ReadLine(), out data)); list.InsertAtEnd(data); break; case 5: do { Console.WriteLine("Insert node: "); }while (!int.TryParse(Console.ReadLine(), out data)); do { Console.WriteLine("Insert node after a particular node: "); }while (!int.TryParse(Console.ReadLine(), out x)); list.InsertAfter(data, x); break; case 6: do { Console.WriteLine("Insert node: "); }while (!int.TryParse(Console.ReadLine(), out data)); do { Console.WriteLine("Insert node before a particular node: "); }while (!int.TryParse(Console.ReadLine(), out x)); list.InsertAfter(data, x); break; case 7: list.DeleteFirstNode(); break; case 8: list.DeleteLastNode(); break; case 9: do { Console.WriteLine("Delete node: "); }while (!int.TryParse(Console.ReadLine(), out data)); list.DeleteNode(data); break; case 10: list.ReverseList(); break; default: Console.WriteLine("Wrong choice! Try again!"); break; } Console.WriteLine(); } Console.WriteLine("Exit"); }