TYPE T
Stack{
T[] queue;
front = 0;
rear = 0;
enQueue(T data){
array size check;
queue[rear++]= data;
}
T deQueue(){
empty check;
return queue[front++];
}
T peekFront(){
empty check;
return queue[front];
}
T peekRear(){
empty check;
return queue[rear];
}
int size(){
return rear;
}
}
TYPE T
Node{
T data;
Node before;
Node next;
}
Queue{
Node front;
Node rear;
int size = 0;
enQueue(T data){
Node newNode = new Node(data, rear, null);
if rear is not null{
rear.next = newNode;
}else{
front = newNode;
}
rear = newNode;
size++;
}
T deQueue(){
front null check;
T data = front.data;
front = front.next;
if front is null{
rear = null;
}else{
front.before = null;
}
size--;
return data;
}
T peekFront(){
front null check;
return front.data;
}
T peekRear(){
rear null check;
return rear.data;
}
int size(){
return size;
}
}