Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
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
C# 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.
c++ 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 exist
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
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. 13PC
Knowledge Booster
Similar questions
- 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_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_forwardStack: 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_forward
- c++ code Screenshot and output is mustarrow_forwardlisp program language please Write down a Lisp function that takes as argument a list and returns another list that contains the same elements but without repetition.arrow_forwardWhat are some of the similarities between string and lists?arrow_forward
- class Queue { private static int front, rear, capacity; private static int queue[]; Queue(int size) { front = rear = 0; capacity = size; queue = new int[capacity]; } // insert an element into the queue static void queueEnqueue(int item) { // check if the queue is full if (capacity == rear) { System.out.printf("\nQueue is full\n"); return; } // insert element at the rear else { queue[rear] = item; rear++; } return; } //remove an element from the queue static void queueDequeue() { // check if queue is empty if (front == rear) { System.out.printf("\nQueue is empty\n"); return; } // shift elements to the right by one place uptil rear else {…arrow_forwardQueue is referred to be as First-In-First-Out (FIFO) list. True or Falsearrow_forwardIn C++ Prepare a queue program for numbers using a menu with the operations: insert, del, display. Consider the size of the queue is 10. The display operation will show the numbers that are in the queue. Hint: OPERATIONS: insert 10,20,30, display them, delete from queue , display the queue . r=-1, f=-1arrow_forward
- C++ Question You need to write a class called LinkedList that implements the following List operations: public void add(int index, Object item); // adds an item to the list at the given index, that index may be at start, end or after or before the // specific element 2.public void remove(int index); // removes the item from the list that has the given index 3.public void remove(Object item); // finds the item from list and removes that item from the list 4.public List duplicate(); // creates a duplicate of the list // postcondition: returns a copy of the linked list 5.public List duplicateReversed(); // creates a duplicate of the list with the nodes in reverse order // postcondition: returns a copy of the linked list with the nodes in 6.public List ReverseDisplay(); //print list in reverse order 7.public Delete_Smallest(); // Delete smallest element from linked list 8.public List Delete_duplicate(); // Delete duplicate elements from a given linked list.Retain the…arrow_forwardplease help in c++arrow_forwardStack: 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. So using the class made in task 1, make a class named as Stack, having following additional functionalities: 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…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning