From 8def0f5b2b568df6c45ead46f6321d8adda0e795 Mon Sep 17 00:00:00 2001 From: prasantbajpai007 <70228248+prasantbajpai007@users.noreply.github.com> Date: Fri, 30 Oct 2020 10:54:42 +0530 Subject: [PATCH] Create queue using linkedlist queue using linkedlist --- queue using linkedlist | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 queue using linkedlist diff --git a/queue using linkedlist b/queue using linkedlist new file mode 100644 index 0000000..0bcadd1 --- /dev/null +++ b/queue using linkedlist @@ -0,0 +1,54 @@ +public class myqueue { + class Node{ + int data; + Node next; + Node(int data) + { + this.data=data; + Node next=null; + + } + } + Node head,rear; + public void enqueue(int add) + { + Node toadd =new Node(add); + if(head==null) + { + head=rear=toadd; + return; + } + rear.next=toadd; + rear=rear.next; + + } + public int dequeue(){ + if(head==null) { + return (Integer) null; + } + Node temp=head; + head=temp.next; + + if(head==null) { + rear=null; + } + return temp.data; + } + public static void main() + { + myqueue q=new myqueue(); + + q.enqueue(1); + q.enqueue(2); + q.enqueue(3); + q.enqueue(4); + q.enqueue(5); + // a=q.dequeue(); + //q.dequeue(); + // q.dequeue(); + System.out.println(q.dequeue()); + } + + +} +