Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18, Problem 3PC
Program Plan Intro
Static Queue Template
Program Plan:
Main.cpp:
- Include required header files.
- Inside “main ()” function,
- Declare a constant variable
- Declare a template
- Manipulate and insert elements into the queue using “enqueue ()” function.
- Delete the queue elements using “dequeue ()” function.
Queue.h:
- Include required header files.
- Create template class
- Declare a class named “Queue”. Inside the class,
- Inside the “private” access specifier,
- Create an object for the template
- Declare required variables.
- Inside “public” access specifier,
- Declare constructor and destructor.
- Declare the functions “enqueue ()”, “dequeue ()”, “isEmpty ()”, “isFull ()”, and “clear ()”.
- Inside the “private” access specifier,
- Declare template class.
- Give definition for the constructor.
- Allocate memory dynamically for the template.
- Assign the values.
- Declare template class.
- Give definition for the destructor.
- Delete queue array and make it as null.
- Declare template class.
- Give function definition for “enqueue ()”.
- Check whether the queue is full using “isFull ()” function.
- If the condition is true then, print “The queue is full”.
- If the condition is not true then,
- Calculate the “rear” position.
- Assign “num” to the “queue_Array [rear]”.
- Increment the variable “numItems”.
- Check whether the queue is full using “isFull ()” function.
- Declare template class.
- Give function definition for “dequeue ()”.
- Check if the queue is empty using “isEmpty ()” function.
- If the condition is true then print “The queue is empty”.
- If the condition is not true then,
- Calculate “front” position.
- Assign the value of “queue_Array [front]” to the variable “num”.
- Decrement the variable “numItems”.
- Check if the queue is empty using “isEmpty ()” function.
- Declare template class.
- Give function definition for “isEmpty ()”.
- Assign “true” to a Boolean variable
- Check if “numItems” is true.
- If the condition is true then assign “false” to the variable.
- Return the Boolean variable.
- Declare template class.
- Give function definition for “isFull ()”.
- Assign “true” to a Boolean variable
- Check if “numItems” is less than “size”
- If the condition is true then assign “false” to the variable.
- Return the Boolean variable.
- Declare template class.
- Give function definition for “clear ()”.
- Decrement queue size and assign it to “front”.
- Decrement queue size and assign it to “rear”.
- Assign 0 to the variable “numItems”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
X1222: Double Ended Queue: Deque
A double ended queue, known as deque, is a queue data structure that allows adding and removing elements from both ends of the queue. Instead of enqueue and dequeue, it
has insert, delete, and get for both front and last of the queue as shown below.
The data stored internally is stored in a ListNodesPlus object. The basic class definition is shown below:
public class Deque {
private ListNodePlus elements;
// code ommitted for space
public void clear() {...};
public int numElements () {...};
public boolean isEmpty() {...};
●
// Implement the following four methods
public void insertFront (E it) { }
public E deleteFront () { }
public void insertLast (E it) { }
public E deleteLast() { }
Write the following four methods:
• insertFront (E it) takes it and adds it to the front of the queue. stored internally in elements. The front of the queue is defined as position 0 in the queue.
● deleteFront () removes the element at the front of the queue and returns it.…
Java Programming
Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection.
Define method add. This method add the any object to list.
Define printAll. This method display all the added object in the list.
Define printAll. This method display all the added object in the list. · Define int count. This method returns the number of objects added in the list.
Define Book search(Object e). This method returns the object being search if not found return null.
Define void remove(int index). This method remove the object in a list
Add a main method with the following menu:1 – Add 2 – Count 3 – Print4 – Search 5 – Delete 6 - Exit
C++ ProgrammingActivity: Queue Linked List
Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow.
#include "queue.h"
#include "linkedlist.h"
class SLLQueue : public Queue {
LinkedList* list;
public:
SLLQueue() {
list = new LinkedList();
}
void enqueue(int e) {
list->addTail(e);
return;
}
int dequeue() {
int elem;
elem = list->removeHead();
return elem;
}
int first() {
int elem;
elem = list->get(1);
return elem;;
}
int size() {
return list->size();
}
bool isEmpty() {
return list->isEmpty();
}
int collect(int max) {
int sum = 0;
while(first() != 0) {
if(sum + first() <= max) {
sum += first();
dequeue();
} else {…
Chapter 18 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Problem Description: 1. Suppose that we want to add a method to a class of queues that will splice two queues together. This method adds to the end of a queue all items that are in a second queue. The header of the method could be as follows: public void splice (QueueInterface anotherQueue) Write this method in such a way that it will work in any class that implements QueueInterface.arrow_forwardC++ ProgrammingActivity: Queue Linked List Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow. SEE ATTACHED PHOTO FOR THE PROBLEM #include "queue.h" #include "linkedlist.h" class SLLQueue : public Queue { LinkedList* list; public: SLLQueue() { list = new LinkedList(); } void enqueue(int e) { list->addTail(e); return; } int dequeue() { int elem; elem = list->removeHead(); return elem; } int first() { int elem; elem = list->get(1); return elem;; } int size() { return list->size(); } bool isEmpty() { return list->isEmpty(); } int collect(int max) { int sum = 0; while(first() != 0) { if(sum + first() <= max) { sum += first();…arrow_forwardc++ Write a client function that returns the back of a queue while leaving the queue unchanged. This function can call any of the methods of the ADT queue. It can also create new queues. The return type is ITemType, and it accepts a queue as a parameter.arrow_forward
- data structure-JAVAarrow_forwardC++ A queue is essentially a waiting list. It’s a sequence of elements with a front and a back. Elements can only be added to the back of the queue and they can only be removed from the front of the queue. Elements are kept in order so that the first element to enter the queue is the first one to leave it.arrow_forwardJAVA CODEarrow_forward
- C++ Code for a QueueThe program should features a Queue class with insert(), remove(), peek(),isFull(), isEmpty(), and size() member functions.The main() program creates a queue of five cells, inserts four items, removes threeitems, and inserts four more. The sixth insertion invokes the wraparound feature. All the items are then removed and displayed. The output looks like this:40 50 60 70 80arrow_forwardCourse: Data Structure and Algorithms Language: C++ Question is well explained Question #2Implement a class for Circular Doubly Linked List (with a dummy header node) which stores integers in unsorted order. Your class definitions should look like as shown below: class CDLinkedList;class DNode {friend class CDLinkedList;private int data;private DNode next;private DNode prev;};class CDLinkedList {private:DNode head; // Dummy header nodepublic CDLinkedList(); // Default constructorpublic bool insert (int val); public bool removeSecondLastValue (); public void findMiddleValue(); public void display(); };arrow_forwardIn C++ Pleasearrow_forward
- You need to implement a class named "Queue" that simulates a basic queue data structure. The class should have the following methods: Enqueue(int value) - adds a new element to the end of the queue Dequeue() - removes the element from the front of the queue and returns it Peek() - returns the element from the front of the queue without removing it Count() - returns the number of elements in the queue The class should also have a property named "IsEmpty" that returns a boolean indicating whether the queue is empty or not. Constraints: The queue should be implemented using an array and the array should automatically resize when needed. All methods and properties should have a time complexity of O(1) You can write the program in C# and use the test cases to check if your implementation is correct. An example of how the class should be used: Queue myQueue = new Queue(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); Console.WriteLine(myQueue.Peek()); // 1…arrow_forward# Create an object from the Queue class. # Queue (with a capital Q) is the class name # queue (with a small q) is the object # created from the "Queue" classarrow_forwardRead this: Complete the code in Visual Studio using C++ Programming Language - Give me the answer in Visual Studio so I can copy*** - Separate the files such as .cpp, .h, or .main if any! Develop a C++ "doubly" linked list class of your own that can hold a series of signed shorts Develop the following functionality: Develop a linked list node struct/class You can use it as a subclass like in the book (Class contained inside a class) You can use it as its own separate class Your choice Maintain a private pointer to a node class pointer (head) Constructor Initialize head pointer to null Destructor Make sure to properly delete every node in your linked list push_front(value) Insert the value at the front of the linked list pop_front() Remove the node at the front of the linked list If empty, this is a no operation operator << Display the contents of the linked list just like you would print a character string operator [] Treat like…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education