static void Main(string[] args) { Page pageFirst = new Page() { Content = "Nowadays, there are various (...)" }; Page pageSecond = new Page() { Content = "Application development is (...)" }; Page pageThird = new Page() { Content = "A lot of applications (...)" }; Page pageFourth = new Page() { Content = "Do you know that modern (...)" }; Page pageFifth = new Page() { Content = "While developing applications (...)" }; Page pageSixth = new Page() { Content = "Could you imagine your (...)" }; LinkedList <Page> pages = new LinkedList <Page>(); pages.AddLast(pageSecond); LinkedListNode <Page> nodePageFourth = pages.AddLast(pageFourth); pages.AddLast(pageSixth); pages.AddFirst(pageFirst); pages.AddBefore(nodePageFourth, pageThird); pages.AddAfter(nodePageFourth, pageFifth); LinkedListNode <Page> current = pages.First; int number = 1; while (current != null) { Console.Clear(); string numberString = $"- {number} -"; int leadingSpaces = (90 - numberString.Length) / 2; Console.WriteLine(numberString.PadLeft(leadingSpaces + numberString.Length)); Console.WriteLine(); string content = current.Value.Content; for (int i = 0; i < content.Length; i += 90) { string line = content.Substring(i); line = line.Length > 90 ? line.Substring(0, 90) : line; Console.WriteLine(line); } Console.WriteLine(); Console.WriteLine($"Quote from \"Windows Application Development Cookbook\" by Marcin Jamro,{Environment.NewLine}published by Packt Publishing in 2016."); Console.WriteLine(); Console.Write(current.Previous != null ? "< PREVIOUS [P]" : GetSpaces(14)); Console.Write(current.Next != null ? "[N] NEXT >".PadLeft(76) : string.Empty); Console.WriteLine(); switch (Console.ReadKey(true).Key) { case ConsoleKey.N: if (current.Next != null) { current = current.Next; number++; } break; case ConsoleKey.P: if (current.Previous != null) { current = current.Previous; number--; } break; default: return; } } }
public static void Main(string[] args) { string menuSelection = "", newNode = "", existingNode = ""; LinkedList ll = new LinkedList(new Node("zzz")); do { newNode = ""; PrintMainMenu(); menuSelection = Console.ReadLine(); Console.Clear(); switch (menuSelection) { case "1": Console.WriteLine("What value you like the new Node to contain?"); newNode = Console.ReadLine(); if (newNode != "") { ll.AddNode(new Node(newNode)); } else { Console.Clear(); Console.WriteLine("Sorry, you must input a value for the Node. Please try again."); } Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "2": Console.WriteLine("What value you like the new Node to contain?"); newNode = Console.ReadLine(); Console.Clear(); Console.WriteLine("What is the value of the existing Node to insert the new Node before?"); existingNode = Console.ReadLine(); if (newNode != "" && existingNode != "") { ll.AddBefore(new Node(newNode), new Node(existingNode)); } else { Console.Clear(); Console.WriteLine("Sorry, you must input a value for both Nodes. Please try again."); } Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "3": Console.WriteLine("What value you like the new Node to contain?"); newNode = Console.ReadLine(); Console.Clear(); Console.WriteLine("What is the value of the existing Node to insert the new Node after?"); existingNode = Console.ReadLine(); if (newNode != "" && existingNode != "") { ll.AddAfter(new Node(newNode), new Node(existingNode)); } else { Console.Clear(); Console.WriteLine("Sorry, you must input a value for both Nodes. Please try again."); } Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "4": Console.WriteLine("What value you like the new Node to contain?"); newNode = Console.ReadLine(); if (newNode != "") { ll.AddLast(new Node(newNode)); } else { Console.Clear(); Console.WriteLine("Sorry, you must input a value for the Node. Please try again."); } Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "5": Console.WriteLine("What is the value of the Node you would like to find?"); existingNode = Console.ReadLine(); if (existingNode != "") { Node checkNode = ll.Find(existingNode); if (checkNode != null) { Console.WriteLine("\nFound!"); } else { Console.WriteLine("\nThat Node doesn't exist."); } } else { Console.Clear(); Console.WriteLine("Sorry, you must input a value for the Node. Please try again."); } Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "6": ll.PrintNodes(); Console.Write("\nPress any key to return to main menu..."); Console.ReadKey(); Console.Clear(); break; case "7": Environment.Exit(0); break; default: Console.WriteLine("That did not match one of the menu options. Try again.\n"); break; } } while (menuSelection != "7"); }