This repository was archived by the owner on Aug 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 740
/
Copy pathQueueUsingLL.cs
60 lines (50 loc) · 1.43 KB
/
QueueUsingLL.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
using System;
using System.Collections;
using System.Collections.Generic;
namespace DataStructures
{
class SimpleQueue
{
private LinkedList<int> queue = new LinkedList<int>();
public void Enqueue(int val) {
queue.AddLast(val);
}
public int Dequeue() {
int ret = queue.First.Value;
queue.RemoveFirst();
return ret;
}
public int Peek() {
return queue.First.Value;
}
public int Size() {
return queue.Count;
}
public bool IsEmpty() {
return queue.Count == 0;
}
public void Print()
{
foreach (int i in queue) Console.Write(i + " ");
}
static void Main(string[] args)
{
SimpleQueue myQueue = new SimpleQueue();
myQueue.Enqueue(55);
myQueue.Enqueue(33);
myQueue.Enqueue(12);
myQueue.Enqueue(77);
myQueue.Enqueue(25);
Console.WriteLine("Current queue: ");
myQueue.Print();
Console.WriteLine();
int n = myQueue.Dequeue();
Console.WriteLine("The dequeued value: {0}", n);
n = myQueue.Dequeue();
Console.WriteLine("The dequeued value: {0}", n);
Console.WriteLine("Current queue: ");
myQueue.Print();
Console.WriteLine();
}
}
}