-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.cs
69 lines (56 loc) · 1.53 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
59
60
61
62
63
64
65
66
67
68
69
using System;
namespace DataStructures
{
class Queue
{
private Node _first, _last;
public void Enqueue(Object item)
{
if (_first == null)
{
_last = new Node((int)item);
_first = _last;
}
else
{
_last.Next = new Node((int)item);
_last = _last.Next;
}
}
public Object Dequeue()
{
if (_first != null)
{
Object item = _first.Data;
_first = _first.Next;
if (_first == null)
{
// Queue is empty
_last = null;
}
return item;
}
return null;
}
/* Example code for Main method:
*
* Console.WriteLine(DateTime.Now.Millisecond);
Console.WriteLine();
var queue = new Queue();
for (var loopCounter = 0; loopCounter < 100; loopCounter++)
{
queue.Enqueue(loopCounter);
Console.WriteLine(loopCounter);
}
Console.WriteLine();
for (var loopCounter = 0; loopCounter < 100; loopCounter++)
{
Console.WriteLine(queue.Dequeue().ToString());
}
Console.WriteLine();
Console.WriteLine(DateTime.Now.Millisecond);
var dummy = Console.ReadLine();
*
*/
}
}