import java.util.;
import java.lang.;
import java.io.*;
class Queue{
int front, rear, size, capacity;
int array[];
Queue(int capacity){
this.capacity = capacity;
front=0;
rear=-1;
size=0;
}
boolean isEmpty(){
return (size==0);
}
boolean isFull(){
return(size==capacity);
}
void enqueue(int item){
if(this.isFull()) return;
else {rear=(rear+1)%capacity;
array[rear]=item;
size=size+1;
}
}
int dequeue(){
if(this.isEmpty()) return Integer.MIN_VALUE;
else { int item;
item=array[front];
front=(front+1)%capacity;
size=size-1;
return item;
}
}
}
class Driver{
public static void main(String[] args){
Queue queue = new Queue(5);
queue.enqueue(1);
queue.enqueue(2);
System.out.println(queue.dequeue());
}
}
This code is the array implementation of queue…
The above code is showing null pointer exception on third line of enqueue() method, can anybody explain me the reason