Hi
IN JAVA please Implement an the ADT List-Based ADT Queue and verify ""isEmpty()", "enqueue()", "dequeue()", "dequeueAll()", and "peak()" operations.
please write main method as well and show output
PROGRAM:
//QNode java
package com.study.HomeworkLib;
class QNode {
int key;
QNode next;
//constructor
public QNode(int key)
{
this.key = key;
this.next = null;
}
}//Queuejava
package com.study.HomeworkLib;
class Queue {
QNode front, rear;
public Queue() {
this.front = this.rear = null;
}
void dequeueAll() {
if (IsEmpty())
return;
//just make front and rear null. Java Garbage collector will take
care of cleaning memory
this.front = this.rear = null;
}
QNode peak() {
if (IsEmpty())
return null;
return this.front;
}
//Method to add an element to the queue.
void enqueue(int key) {
QNode temp = new QNode(key);
//check if queue is empty
if (this.rear == null) {
this.front = this.rear = temp;
return;
}
//add element ti the end
this.rear.next = temp;
this.rear = temp;
}
boolean IsEmpty() {
return this.front == null;
}
//Method to remove an element from queue.
QNode dequeue() {
//check emptinesss
if (IsEmpty())
return null;
// Store previous front and move front one node ahead
QNode temp = this.front;
this.front = this.front.next;
//handle single node case
if (this.front == null)
this.rear = null;
return temp;
}
}
//Test.java
package com.study.HomeworkLib;
public class Test {
public static void main(String[] args) {
Queue q = new Queue();
q.enqueue(100);
q.enqueue(200);
System.out.println("Element Dequed is :" + q.dequeue().key);
q.dequeue();
q.enqueue(300);
q.enqueue(400);
q.enqueue(500);
System.out.println("Element Dequed is :" +q.dequeue().key);
}
}
PROGRAM SCREENSHOTS:


output:

Hi IN JAVA please Implement an the ADT List-Based ADT Queue and verify ""isEmpty()", "enqueue()", "dequeue()",...