Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 6PC
Program Plan Intro
Dynamic String Queue
Program Plan:
- Include the required header files.
- Declare a class Dynque that creates a queue and store all the elements in the queue.
- Declare all the variables present in the class.
- Declare the front and rear pointers and the number of items.
- Create a constructor to allocate elements in queue.
- Create a destructor to deallocate elements in queue.
- Create a function void Dynque<T>::enqueue(T val)that inserts the value in the variable val at the rear end of queue.
- Create a function void Dynque<T>::dequeue(T &val)that removes the value at the front of the queue, and copies it into val.
- Create a boolean function to check if queue is empty and a function clear to dequeue all elements present in the queue.
- Declare the main function.
- Prompt the user to enqueue 5 strings into the queue.
- Dequeue and retrieve all items present in the queue.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
java data structure
Queue:
Q4: A program performs the following operations on an empty queue Q:
Q.enqueue(24)
Q.enqueue(74)
Q.enqueue(34)
Q.first()
Q.dequeue()
Q.enqueue(12)
Q.dequeue()
Please show the queue contents at the end of these operations. Clearly show the front of the queue.
None
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.
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();…
Chapter 18 Solutions
Starting Out With C++: Early Objects (10th 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. 14PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- P7arrow_forwardC# language Write a program that creates a Queue or Stack (your choice) that represents a list of work orders. This program should use loop, allowing the user to push and pop items on the stack / queue. The program should also allow the user to print all the items in the stack / queue to the console.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_forward
- data structure Create a Java program using a Linked list by adding 5 nodes and then removing 1 node from the list. The node entries can be either Numbers (Int) or Characters (String).arrow_forwardc++ data structures ADT Unsorted List The specifications for the Unsorted List ADT states that the item to be deleted is in the list. Rewrite the specifications for DeleteItem so that the list is unchanged if the item to be deleted is not in the list. Rewrite the specifications for DeleteItem so that all copies of the item to be deleted are removed if they existarrow_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. #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 {…arrow_forward
- C++ Queue LinkedList, Refer to the codes I've made as a guide and add functions where it can add/insert/remove function to get the output of the program, refer to the image as an example of input & output. Put a comment or explain how the program works/flow.arrow_forwardJava data strucarrow_forwardMultiple choice in data structures void stack::do(){ for(int i=0li<=topindex/2;i++){ T temp=entry[i]; entry[i]=entry[topindex-i-1]; entry[topindex-1-i]=temp;} } What is this method do? a. swap the first item with last item b. replace each item with next item value c. doesn't do any thing d. reverse the stackarrow_forward
- Stack: Stacks are a type of container with LIFO (Last In First Out) type of working, where a new element is added at one end and (top) an element is removed from that end only. Your Stack should not be of the fixed sized. It should be able to grow itself. bool empty() : Returns whether the Stack is empty or not. Time Complexity should be: O(1) bool full() : Returns whether the Stack is full or not. Time Complexity should be: O(1)int size() : Returns the current size of the Stack. Time Complexity should be: O(1)Type top () : Returns the last element of the Stack. Time Complexity should be: O(1) void push(Type) : Adds the element of type Type at the top of the stack. Time Complexity should be: O(1) Type pop() : Deletes the top most element of the stack and returns it. Time Complexity should be: O(1) Write non-parameterized constructor for the above class. Write Copy constructor for the above class. Write Destructor for the above class. Now write a global function show stack which…arrow_forwarddata structure javaarrow_forwardc++ code Screenshot and output is mustarrow_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