-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack.cs
57 lines (46 loc) · 1.09 KB
/
stack.cs
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
51
52
53
54
55
56
57
using System;
using System.Collections;
class EventDemo
{
static void Main(string[] args)
{
Stack s = new Stack();
showPush(s, 5);
showPush(s, 10);
showPush(s, 23);
showPush(s, 26);
showPush(s, 31);
showPush(s, 33);
showPush(s, 35);
showPop(s);
showPop(s);
showPop(s);
showPop(s);
showPop(s);
showPop(s);
showPop(s);
try{
showPop(s);
}
catch(InvalidOperationException){
Console.WriteLine("Empty Stack");
}
Console.ReadKey();
}
static void showPush(Stack s, int i){
s.Push(i);
Console.WriteLine("Push(" + i + ")");
Console.Write("Stack: ");
foreach(int n in s)
Console.Write( n + ", ");
Console.WriteLine();
}
static void showPop(Stack s){
Console.Write("Pop->");
Console.WriteLine((int) s.Pop());
Console.Write("Stack: ");
foreach (int n in s)
Console.Write(n + ", ");
Console.WriteLine();
}
}