Here is the Code:
class Program
{
static void Main(string[] args)
{
Quene q = new Quene();
// This Solution is written by me and is not completely tested. Please comment if you found any alternative solutions or any enhancement to my solution.
q.add(1);
q.add(2);
q.add(3);
q.add(4);
q.add(5);
q.add(6);
q.add(7);
q.display();
q.pop();
q.display();
}
}
public class node
{
public int data { get; set; }
public node next { get; set; }
public node(int _data)
{
data = _data;
}
}
public class Quene
{
public node head { get; set; }
public node tail { get; set; }
public void add(int data)
{
node n = new node(data);
if (head == null)
{
tail = n;
head = n;
}
else
{
tail.next = n;
tail = n;
}
}
public void pop()
{
if (head != null)
{
head = head.next;
}
}
public void display()
{
var temp = head;
Console.WriteLine("________________");
while (temp != null)
{
Console.WriteLine(temp.data);
temp = temp.next;
}
Console.WriteLine("________________");
}
}
Output:
________________
1
2
3
4
5
6
7
________________
________________
2
3
4
5
6
7
________________
Press any key to continue . . .
Popular Posts
-
Here is the code: // => Brute Force Solution: O(m* n) static long arrayManipulation(int n, int[][] queries) { ...
-
Whatever it is one fine day everyone on this planet who are born have to die for sure. When you are close ones are with you, you wont know ...
-
HTML: <div class="outer-container"> <div class="inner-container"> <div class="t...
No comments:
Post a Comment