Skip to content

Kavya saxena patch 1 #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
57 changes: 57 additions & 0 deletions Competitive Coding/Linked List/queue .java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package linkedlist;
public class Node
{
public int data;
public Node link;
}
public class Queue
{
public Node rear=null;
public Node top=null;
public void push(int x)
{
Node temp=new Node();
temp.data=x;
if(top==null)
{
rear=temp;
top=temp;
temp.link=null;
}
else
{
Node ptr=rear;
while(ptr.link!=null)
{
ptr=ptr.link;
}
ptr.link=temp;
temp.link=null;
}
}
public void pop()
{
rear=rear.link;
}
public void display()
{
Node ptr=rear;
while(ptr!=null)
{
System.out.println(ptr.data+" ");
ptr=ptr.link;
}
}
public static void main(String args[])
{
Queue t=new Queue();
t.push(1);
t.push(2);
t.push(3);
t.push(4);
t.push(5);
t.push(6);
t.pop();
t.display();
}
}