-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue.cs
58 lines (47 loc) · 1.17 KB
/
queue.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
58
using System;
using System.Collections;
class EventDemo
{
static void Main(string[] args)
{
Queue q = new Queue();
showEnqueue(q, 5);
showEnqueue(q, 10);
showEnqueue(q, 23);
showEnqueue(q, 26);
showEnqueue(q, 31);
showEnqueue(q, 33);
showEnqueue(q, 35);
showDequeue(q);
showDequeue(q);
showDequeue(q);
showDequeue(q);
showDequeue(q);
showDequeue(q);
showDequeue(q);
try
{
showDequeue(q);
}
catch(InvalidOperationException){
Console.WriteLine("Empty Queue");
}
Console.ReadKey();
}
static void showEnqueue(Queue q, int i){
q.Enqueue(i);
Console.WriteLine("Enqueue(" + i + ")");
Console.Write("Queue: ");
foreach(int n in q)
Console.Write( n + ", ");
Console.WriteLine();
}
static void showDequeue(Queue q){
Console.Write("Dequeue->");
Console.WriteLine((int) q.Dequeue());
Console.Write("Queue: ");
foreach (int n in q)
Console.Write(n + ", ");
Console.WriteLine();
}
}