Created
February 24, 2021 06:34
-
-
Save akashkumarcs19/149bf8fbd5fbf93cc68ec3469cefefed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue1 { | |
static Node head; | |
Node beginning = null; | |
Node topOfQueue = null; | |
static class Node { | |
int data; | |
Node next; | |
public Node(int data) { | |
this.data = data; | |
next = null; | |
} | |
} | |
public boolean isEmpty(){ | |
if(beginning == null && topOfQueue == null) | |
return true; | |
else return false; | |
} | |
public void enqueueFront(Node newnode){ | |
if(isEmpty()){ | |
beginning = newnode; | |
topOfQueue = newnode; | |
} | |
else{ | |
newnode.next=beginning; | |
beginning = newnode; | |
} | |
} | |
public void enqueueRear(Node newnode){ | |
if(isEmpty()){ | |
topOfQueue = newnode; | |
beginning = newnode; | |
} | |
else{ | |
topOfQueue.next = newnode; | |
topOfQueue = newnode; | |
newnode.next = null; | |
} | |
} | |
public int dequeueFront(){ | |
int temp = 0; | |
if(isEmpty()){ | |
System.out.println("UnderFlow Condition"); | |
} | |
else { | |
temp = beginning.data; | |
beginning = beginning.next; | |
} | |
return temp; | |
} | |
public int dequeRear(){ | |
Node temp = beginning; | |
int k = 0; | |
if(isEmpty()){ | |
System.out.println("Underfloww"); | |
} | |
else{ | |
while(temp.next!=topOfQueue){ | |
temp=temp.next; | |
} | |
k = topOfQueue.data; | |
topOfQueue = temp; | |
topOfQueue.next =null; | |
} | |
return k; | |
} | |
} | |
} | |
public class DoubleEndedQueue { | |
public static void main(String[] args) { | |
Queue1 quee = new Queue1(); | |
quee.beginning=new Node(15); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment