A generic queue is a general queue storage that can store an unlimited number of objects.
In this lab, you need to implement two types of the generic queue including Queue and Deque.
The Java code of this module includes a class that represent Queues and was mentioned briefly
during the lecture, therefore if you need to, please revisit the java code.
The second special type of containers is called a Deque. A deque is a special type of queue that is
double ended. It means that elements can be added to the queue at both ends and removing can
be from both ends. In essence, a deque follows both a FIFO (First in, First out) and a LIFO (Last
In, First Out) rules to insert/remove from/to the queue. This means that a deque can play the role
of a queue and a stack at the same time. You can imagine a stack as a plate dispenser. When you
add a plate, you add it to the top of the dispenser. When you remove a plate, you remove it from
the top again. However, for a queue, you can imagine a queue of students waiting in line. The first
student who comes into the line is the first student served and hence removed from the line.
For the stack behavior of a deque, there are two main and two auxiliary methods:
push(object): This method adds the object to the stack. IN other words, the object is added at the
front.
pop(): removes the last element that was added, from the stack. In other words, the object is
removed from the front.
top(): returns the element, which is at the top of the stack, without removing it.
getSize(): returns the number of elements in the stack.
Your job for this lab, is to complete GenericQueue, Queue and Deque class. I have written a
comment, where you need to insert your code.
3.1. Class GenericQueue
The names of the methods in this class explain themselves. If you need more clarification, please
read the javaDoc for these methods.
3.2. Class Queue
While Queue Is-A generic queue, it follows the rule of Queue data structure (FIFO), therefore all
the methods should be implemented in a way that the rule is followed.
This class has an instance variable that holds all the items. The rest of the methods are self-
explanatory.
3.3. Class Deque
The Deque class is a special type of a Queue that was explained above. So the deque acts as a
queue and has additional methods that represent the stack behaviour.
This class has a constructor that uses the list that contains the data. To implement the rest of the
methods see their javaDoc.
import java.util.*;
import java.io.*;
/**
* This class is a GenericQueue that holds an unlimited number of
* objects. It is able to remove objects and add objects.
*/
public class GenericQueue {
// No instance variable should be defined for this class.
/**
* This method adds the <code> obj </code> to the GenericQueue.
* @param obj is the object that is added to the GenericQueue.
*/
void add(Object object) {
// insert your code here
}
/**
* This method removes the object from the GenericQueue
* @return returns the removed.
A generic queue is a general queue storage that can store an.pdf
1. A generic queue is a general queue storage that can store an unlimited number of objects.
In this lab, you need to implement two types of the generic queue including Queue and Deque.
The Java code of this module includes a class that represent Queues and was mentioned briefly
during the lecture, therefore if you need to, please revisit the java code.
The second special type of containers is called a Deque. A deque is a special type of queue that is
double ended. It means that elements can be added to the queue at both ends and removing can
be from both ends. In essence, a deque follows both a FIFO (First in, First out) and a LIFO (Last
In, First Out) rules to insert/remove from/to the queue. This means that a deque can play the role
of a queue and a stack at the same time. You can imagine a stack as a plate dispenser. When you
add a plate, you add it to the top of the dispenser. When you remove a plate, you remove it from
the top again. However, for a queue, you can imagine a queue of students waiting in line. The first
student who comes into the line is the first student served and hence removed from the line.
For the stack behavior of a deque, there are two main and two auxiliary methods:
push(object): This method adds the object to the stack. IN other words, the object is added at the
front.
pop(): removes the last element that was added, from the stack. In other words, the object is
removed from the front.
top(): returns the element, which is at the top of the stack, without removing it.
getSize(): returns the number of elements in the stack.
Your job for this lab, is to complete GenericQueue, Queue and Deque class. I have written a
comment, where you need to insert your code.
3.1. Class GenericQueue
The names of the methods in this class explain themselves. If you need more clarification, please
read the javaDoc for these methods.
3.2. Class Queue
While Queue Is-A generic queue, it follows the rule of Queue data structure (FIFO), therefore all
the methods should be implemented in a way that the rule is followed.
This class has an instance variable that holds all the items. The rest of the methods are self-
explanatory.
3.3. Class Deque
The Deque class is a special type of a Queue that was explained above. So the deque acts as a
queue and has additional methods that represent the stack behaviour.
This class has a constructor that uses the list that contains the data. To implement the rest of the
methods see their javaDoc.
import java.util.*;
import java.io.*;
/**
* This class is a GenericQueue that holds an unlimited number of
* objects. It is able to remove objects and add objects.
*/
public class GenericQueue {
// No instance variable should be defined for this class.
2. /**
* This method adds the <code> obj </code> to the GenericQueue.
* @param obj is the object that is added to the GenericQueue.
*/
void add(Object object) {
// insert your code here
}
/**
* This method removes the object from the GenericQueue
* @return returns the removed object.
*/
Object remove() {
// insert your code here. You may want to change the return value.
return null;
}
/**
* @return It returns the number of elements in the GenericQueue.
*/
int getSize() {
// insert your code here. You may need to change the return value.
return 0;
}
}
/**
*
* This class simulates a Queue, which is a data structure that insert and remove data
* by FIFO (first-in, first-out) rule
*
*/
class Queue extends GenericQueue{
ArrayList<Object> queue;
/**
* This is the constructor that initializes the <code> queue </code>
*/
public Queue() {
}
/**
* This method adds the object into the Queue.
3. * Please note that the rule of the queue insertion/removal is
* First in, First out.
* @param obj is the object that is added to the queue.
*/
@Override
public void add(Object obj) {
}
/**
* This method removes an object from the Queue.
* Please note that the rule of the queue insertion/removal is
* First in, First out.
*/
@Override
public Object remove() {
return null;
}
/**
* @return returns the object which is in front of the queue.
*/
public Object top() {
return null;
}
/**
* Returns the number of items in the queue.
*/
@Override
public int getSize(){
return 0;
}
}
/**
*
* This class simulates a Deque, which is a data structure that insert and remove data
* by FILO (first-in, last-out) rule
*
*/
class Deque extends Queue{
/**
* This is the constructor that initializes the <code> deque </code>
4. */
public Deque() {
}
/**
* This method adds an object to the deque treated as a stack.
* Please note that the rule of the deque insertion/removal is
* both First in, first out (FIFO), as well as Last in, First out (LIFO)
*/
public void push(Object obj) {
}
/**
* This method removes an object from the deque treated as a stack.
* Please note that the rule of the deque insertion/removal is
* both First in, first out (FIFO), as well as Last in, First out (LIFO)
*/
public Object pop() {
return null;
}
}
import java.util.*;
import java.io.*;
/**
* This class is a GenericQueue that holds an unlimited number of
* objects. It is able to remove objects and add objects.
*/
public class GenericQueue {
// No instance variable should be defined for this class.
/**
* This method adds the <code> obj </code> to the GenericQueue.
* @param obj is the object that is added to the GenericQueue.
*/
void add(Object object) {
// insert your code here
}
/**
* This method removes the object from the GenericQueue
5. * @return returns the removed object.
*/
Object remove() {
// insert your code here. You may want to change the return value.
return null;
}
/**
* @return It returns the number of elements in the GenericQueue.
*/
int getSize() {
// insert your code here. You may need to change the return value.
return 0;
}
}
/**
*
* This class simulates a Queue, which is a data structure that insert and remove data
* by FIFO (first-in, first-out) rule
*
*/
class Queue extends GenericQueue{
ArrayList<Object> queue;
/**
* This is the constructor that initializes the <code> queue </code>
*/
public Queue() {
}
/**
* This method adds the object into the Queue.
* Please note that the rule of the queue insertion/removal is
* First in, First out.
* @param obj is the object that is added to the queue.
*/
@Override
public void add(Object obj) {
}
/**
* This method removes an object from the Queue.
6. * Please note that the rule of the queue insertion/removal is
* First in, First out.
*/
@Override
public Object remove() {
return null;
}
/**
* @return returns the object which is in front of the queue.
*/
public Object top() {
return null;
}
/**
* Returns the number of items in the queue.
*/
@Override
public int getSize(){
return 0;
}
}
/**
*
* This class simulates a Deque, which is a data structure that insert and remove data
* by FILO (first-in, last-out) rule
*
*/
class Deque extends Queue{
/**
* This is the constructor that initializes the <code> deque </code>
*/
public Deque() {
}
/**
* This method adds an object to the deque treated as a stack.
* Please note that the rule of the deque insertion/removal is
* both First in, first out (FIFO), as well as Last in, First out (LIFO)
*/
7. public void push(Object obj) {
}
/**
* This method removes an object from the deque treated as a stack.
* Please note that the rule of the deque insertion/removal is
* both First in, first out (FIFO), as well as Last in, First out (LIFO)
*/
public Object pop() {
return null;
}
}