-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.cs
More file actions
73 lines (57 loc) · 1.3 KB
/
Copy pathQueue.cs
File metadata and controls
73 lines (57 loc) · 1.3 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Task22
{
public class MyQueue<T>
{
LinkedNode<T>? front;
LinkedNode<T>? back;
LinkedNode<T>? newNode;
int count = 0;
public MyQueue()
{
front = back = null;
}
public bool IsEmpty()
{
return front == null && back == null;
}
public void Enqueue(T value)
{
newNode = new LinkedNode<T>(value);
if (back == null)
{
front = back = newNode;
}
else
{
back.next = newNode;
back = newNode;
}
count++;
}
public void Dequeue()
{
if (front == null)
{
Console.WriteLine("Oops! Queue is empty!");
}
LinkedNode<T>? current = front;
front = front.next;
count--;
if (front == null)
{
back = null;
}
Console.WriteLine("{0}", current.value);
}
public int Count()
{
return count;
}
}
}