-
-
Save neer2808/e170a098e7072238d7626e296f770c51 to your computer and use it in GitHub Desktop.
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); | |
} | |
} |
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;
}
}
class DoubleEndedQueue {
public static void main(String[] args) {
Queue1 quee = new Queue1();
quee.beginning = new Queue1.Node(15);
System.out.println(quee.dequeueFront());
}
}
one extra Bracket
remove the last brace before starting the DoubleEndedQueue class
and here in main method you are creating object of node class
write code
queue.beginning = new Queue1.Node(15)