C# OOP: Queue

Operations menu of Queue

Step 8: Displaying a menu of choices

To help the user feels friendly with your Queue data structure, you need to provide a list of choices to let the user interact with the program. This can be done by the following C#(Csharp) code:

public static void select()

 Queue<int> mylist = new Queue<int>();
 ListNode<int> temp;
 int val, ch;
 char yes = 'y';
//display menu
 while (yes == 'y')
   Console.Write("Enter your choice:");
   ch = int.Parse(Console.ReadLine().ToString());

  switch (ch)

  case 1:
   val = int.Parse(Console.ReadLine());

  case 2:
    temp = mylist.removeAtBack();

  case 3:
     Console.WriteLine("Number of items:" + mylist.countitem());
  case 4:
   if (mylist.findmax() != null && mylist.findmin() != null)
   Console.WriteLine("Min item:{0}\nMax item:{1}", mylist.findmin().val,  mylist.findmax().val);

  case 5: Console.Write("Find what?");
    val = int.Parse(Console.ReadLine());
    temp = mylist.find(val);
    if (temp != null) Console.WriteLine("Found {0}", temp.val);
    else Console.WriteLine("Not found"); break;
  case 6:
    Console.WriteLine("All items:");

   case 7: Environment.Exit(0); break;

   default: Console.WriteLine("Invalid choice!"); break;


  Console.Write("Continue? Press y to continue:");
   yes = char.Parse(Console.ReadLine());



public static void showmenu()
  Console.WriteLine("Queue Operations Menu");
  Console.WriteLine("1.Add a new item");
  Console.WriteLine("2.Delete an item");
  Console.WriteLine("3.Show number of items");
  Console.WriteLine("4.Show min and max items");
  Console.WriteLine("5.Find an item");
  Console.WriteLine("6.Show all items");



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.