SlideShare a Scribd company logo
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 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.
* 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)
*/
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
* @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.
* 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)
*/
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;
}
}

More Related Content

PPT
Queue Data Structure
PPT
Queue Data Structure
PPT
queueDATA STRUCTURES AND ITS OPERATIONS IMPLEMETED WITH EXAMPLES
DOCX
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
DOCX
Files to submitProperQueue.javaCreate this file and implement .docx
PPT
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
PDF
In java , I want you to implement a Data Structure known as a Doubly.pdf
PDF
JAVA A double-ended queue is a list that allows the addition and.pdf
Queue Data Structure
Queue Data Structure
queueDATA STRUCTURES AND ITS OPERATIONS IMPLEMETED WITH EXAMPLES
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Files to submitProperQueue.javaCreate this file and implement .docx
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
In java , I want you to implement a Data Structure known as a Doubly.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf

Similar to A generic queue is a general queue storage that can store an.pdf (20)

PPTX
Queue collection of Frame work in oops through java
PPT
stack and queue array implementation, java.
PPT
stack and queue array implementation in java.
PDF
Introduction and BackgroundIn recent lectures we discussed usi.pdf
PPT
05-stack_queue.ppt
DOCX
PDF
stacks and queues class 12 in c++
PPTX
queue.pptx
PDF
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
PPT
The Queue in Data structure and algorithm
PDF
Description (Part A) In this lab you will write a Queue implementati.pdf
PPTX
PPTX
module2a it is module 2 so it is module 2.pptx
PPT
2 b queues
PPTX
stacks and queues for public
PPTX
Collection implementation classes - Arraylist, linkedlist, Stack
PPTX
Queue Data Structure
PPTX
Module-1 Updated Collection Framework.pptx
PPTX
Unit ii linear data structures
PPTX
Queues
Queue collection of Frame work in oops through java
stack and queue array implementation, java.
stack and queue array implementation in java.
Introduction and BackgroundIn recent lectures we discussed usi.pdf
05-stack_queue.ppt
stacks and queues class 12 in c++
queue.pptx
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
The Queue in Data structure and algorithm
Description (Part A) In this lab you will write a Queue implementati.pdf
module2a it is module 2 so it is module 2.pptx
2 b queues
stacks and queues for public
Collection implementation classes - Arraylist, linkedlist, Stack
Queue Data Structure
Module-1 Updated Collection Framework.pptx
Unit ii linear data structures
Queues
Ad

More from adhityafashion (20)

PDF
A Health Behaviour in Schoolaged Children study found that .pdf
PDF
A group of n people were removed from the hotel After a mon.pdf
PDF
A ince barsakta ya emlsifikasyon sreci B dklamay dzenl.pdf
PDF
A is a nonempty set and G is a finite group that can be see.pdf
PDF
a In a punctuated module new species change most as they .pdf
PDF
A health system has forecast net patient revenue in the firs.pdf
PDF
a Identify all NE throughout 3 you are only required to p.pdf
PDF
A Imagine you are a communication consultant giving advice .pdf
PDF
a Identificar y discutir los factores bsicos de comunicaci.pdf
PDF
A hoverboard is a levitating board similar in shape and size.pdf
PDF
A hypertonic solution is prepared by the addition of sucrose.pdf
PDF
A hospital is trying to cut down on emergency room wait time.pdf
PDF
A healthy female Labrador retriever was mated with two healt.pdf
PDF
A football team consists of 19 each freshmen and sophomores .pdf
PDF
A group of employees of Unique Services will be surveyed abo.pdf
PDF
A group of college DJs surveyed students to find out what mu.pdf
PDF
a Given that XX1X2Xn represents a random sample of .pdf
PDF
A Genler aras sekanslar insan genomunun gt60n oluturur.pdf
PDF
A financial analyst is interested in estimating the proporti.pdf
PDF
A genetic disorder shows cytoplasmic inheritance A heteropl.pdf
A Health Behaviour in Schoolaged Children study found that .pdf
A group of n people were removed from the hotel After a mon.pdf
A ince barsakta ya emlsifikasyon sreci B dklamay dzenl.pdf
A is a nonempty set and G is a finite group that can be see.pdf
a In a punctuated module new species change most as they .pdf
A health system has forecast net patient revenue in the firs.pdf
a Identify all NE throughout 3 you are only required to p.pdf
A Imagine you are a communication consultant giving advice .pdf
a Identificar y discutir los factores bsicos de comunicaci.pdf
A hoverboard is a levitating board similar in shape and size.pdf
A hypertonic solution is prepared by the addition of sucrose.pdf
A hospital is trying to cut down on emergency room wait time.pdf
A healthy female Labrador retriever was mated with two healt.pdf
A football team consists of 19 each freshmen and sophomores .pdf
A group of employees of Unique Services will be surveyed abo.pdf
A group of college DJs surveyed students to find out what mu.pdf
a Given that XX1X2Xn represents a random sample of .pdf
A Genler aras sekanslar insan genomunun gt60n oluturur.pdf
A financial analyst is interested in estimating the proporti.pdf
A genetic disorder shows cytoplasmic inheritance A heteropl.pdf
Ad

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Presentation on HIE in infants and its manifestations
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Complications of Minimal Access Surgery at WLH
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Lesson notes of climatology university.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Computing-Curriculum for Schools in Ghana
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Presentation on HIE in infants and its manifestations
Anesthesia in Laparoscopic Surgery in India
Complications of Minimal Access Surgery at WLH
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Lesson notes of climatology university.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf

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; } }