-
Notifications
You must be signed in to change notification settings - Fork 6
/
ADT_Stacks.vb
50 lines (47 loc) · 1.41 KB
/
ADT_Stacks.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'Task 2.1 Stacks
Module Module1
Dim StackPtr As Integer
Dim Stack(0 To 9) As String
Sub Main()
StackPtr = 0
Dim MenuChoice As Integer = 0
While MenuChoice <> 4
Console.WriteLine("1. To PUSH to STACK")
Console.WriteLine("2. To POP from STACK")
Console.WriteLine("3. Traverse STACK")
Console.WriteLine("4. To EXIT this module.")
MenuChoice = Console.ReadLine()
Select Case MenuChoice
Case 1 : cmdPush_Click()
Case 2 : cmdPop_Click()
Case 3 : cmdTraverse()
Case 4
Case Else : Console.WriteLine("Wrong choice. Please try again.")
End Select
End While
End Sub
Sub cmdPop_Click()
If StackPtr < 1 Then
Console.WriteLine("Underflow")
Exit Sub
End If
StackPtr = StackPtr - 1
Console.WriteLine(Stack(StackPtr))
End Sub
Sub cmdPush_Click()
Dim newVal As String
Console.WriteLine("Enter new Value: ")
newVal = Console.ReadLine()
If StackPtr > 9 Then
Console.WriteLine("Overflow")
Exit Sub
End If
Stack(StackPtr) = newVal
StackPtr = StackPtr + 1
End Sub
Sub cmdTraverse()
For count = 9 To 0 Step -1
Console.WriteLine(Stack(count))
Next
End Sub
End Module