-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueUsingLinkedList.cs
More file actions
82 lines (68 loc) · 1.69 KB
/
Copy pathQueueUsingLinkedList.cs
File metadata and controls
82 lines (68 loc) · 1.69 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algorithms.Problem.Queues
{
public class Node
{
public int _value;
public Node next;
public Node(int val)
{
this._value = val;
}
}
[TestClass]
public class QueueUsingLinkedList
{
private Node head;
private Node tail;
public void push(int value)
{
Node newNode = new Node(value);
if (this.tail == null)
{
this.tail = newNode;
this.head = this.tail;
return;
}
this.tail.next = newNode;
this.tail = this.tail.next;
}
public int pop()
{
if (this.head == null)
return -1;
Node node = this.head;
this.head = this.head.next;
if (this.head == null)
{
this.tail = null;
}
return node._value;
}
public void Display()
{
Node temp = this.head;
while (temp != null)
{
System.Diagnostics.Debug.WriteLine(temp._value);
temp = temp.next;
}
}
[TestMethod]
public void TestQueueUsingLinkedList()
{
QueueUsingLinkedList queue = new QueueUsingLinkedList();
queue.push(1);
queue.push(2);
queue.push(3);
queue.push(4);
queue.push(5);
queue.Display();
}
}
}