I am learning the Queue Data structure.I want to create Queue with linked list.I want to program ouput : 10 20 Program output: Queue empty -1 Queue empty -1
Where am I making mistakes?
The code is as given below:
class Node {
int x;
Node next;
Node (int x){
this.x=x;
next=null;
}
}
public class QueQueLinked {
static Node root=null;
static Node latest=null;
public static void enque(int x){
if(root==null){
Node root=new Node(x);
root.x=x;
root.next=null;
latest=root;
}
else{
latest.next=new Node(x);
latest=latest.next;
latest.next=null;
}
}
public static int deque(){
if(root==null){
System.out.println("Queque empty");
return -1;
}
int value=root.x;
root=root.next;
return value;
}
public static void main(String[] args) {
enque(10);
enque(20);
System.out.println(deque());
System.out.println(deque());
}
}