VB.NET tutorial-menu circularly linked list


VB.NET OOP example

Menu to operate circularly linked list

Step 8: Display a menu of choices

To show the menu that allow the user to choose an operation on the linked list, you need the showmenu() and select() functions as shown below:


Public Sub showmenu()
 
        Console.WriteLine("===============================")
        Console.WriteLine("Circularly LinkedList Operations Menu")
        Console.WriteLine("===============================")
        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")
        Console.WriteLine("7.Exit")
 
    End Sub
    Public Sub SelectChoice()
        Dim mylist As CirLinkedList = New CirLinkedList()
        Dim val, ch, pos As Integer
        Dim yes As String = "y"
 
        While String.Compare(yes, "y") = 0
            Console.Write("Enter your choice:")
            ch = CInt(Console.ReadLine())
            Select Case ch
                Case 1
                    Console.Write("Value:")
                    val = CInt(Console.ReadLine())
                    Console.Write("Position:")
                    pos = CInt(Console.ReadLine())
                    mylist.insert(val, pos)
                Case 2
                    Console.Write("Position:")
                    pos = CInt(Console.ReadLine())
                    mylist.delete(pos)
 
                Case 3

                    Console.WriteLine("Number of items:{0}", mylist.countitem())
                Case 4

                    If Not IsNothing(mylist.findmin()) And Not IsNothing(mylist.findmax()) Then

                        Console.WriteLine("Min item:{0}/Max item:{1}", mylist.findmin().val, mylist.findmax().val)
                    End If
 
                Case 5
                    Console.Write("Find what:")
                    val = CInt(Console.ReadLine())
                    If Not IsNothing(mylist.find(val)) Then

                        Console.WriteLine("Found:{0}", mylist.find(val).val)
                    Else : Console.WriteLine("Not found")
                    End If
                Case 6
                    Console.WriteLine("All items in the list:")
                    mylist.printlist()
                Case 7 : Environment.Exit(0)
                Case Else : Console.WriteLine("Invalid choice")
            End Select
 
            Console.Write("Continue? Press y:")
            yes = Console.ReadLine().ToString()
 
        End While


Comments

CAPTCHA image




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.