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
Question
Chapter 18, Problem 17RQE
Program Plan Intro
Pseudocode:
Pseudocode is an in-depth yet readable expression of what a computer program or
Stack:
Stack is a linear data structure which follows a set of particular orders in which operations are performed. It follows Last in First out (LIFO) order or First in Last out (FILO). It performs basic operations like push, pop or seek.
Queue:
Queue is an abstract data structure that is similar to stack but is open at both ends. It Follows First In First Out (FIFO) order. It performs basic operation like enqueue and dequeue.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Refer to the operations below:
Add (10 + 5)
Add (4+8)
Add (7*2)
Add (90 – 3)
Print list Print peek Remove an item from the list Print list
1.1 Implement the operations above into a Queue structure called q1.
1.2 Implement the operations above into a Stack structure called s1.
Please convert the code from C Language
#include <bits/stdc++.h>
using namespace std;
struct Queue {
stack<int> s1, s2; // stl used
// Enqueue an item to the queue
void enQueue(int x) {
// Push item into the first stack
s1.push(x);
}
// Dequeue an item from the queue
int deQueue() {
// if both stacks are empty
if (s1.empty() && s2.empty()){
cout << "Queue is empty";
exit(0);
}
// if s2 is empty, move elements from s1
if (s2.empty()) {
while (!s1.empty()) {
s2.push(s1.top()); // using stl operation top()
s1.pop();
}
}
// return the top item from s2
int x = s2.top();
s2.pop();
return x;
}
};
// main function
int main() {
Queue q;
int x,count=0;
cout<<"press 0 to stop push operaton, else enqueue integers"<<endl;
cin>>x;
while(x){
q.enQueue(x);
count++;
cin>>x;
}
cout<<"dequeueing...."<<endl;
while(count){
cout<<q.deQueue()<<endl;
count--;
}
cout<<"execution successful"<<endl;
return 0;
}…
Stack, Queue and Deque5.1. Understand the basic operations for Stack, Queue and DequeExample: Suppose that Queue q is implemented by a circular array data with the size 3. Please drawthe state of the Queue q and circular array data after each of the following steps.1) Queue q = new Queue();2) q.enqueue(5);3) q.enqueue (2);4) q.enqueue (9);
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
Similar questions
- Q. Difference between Stack and Queue Data Structures. Write down key differences. Write some code snippets. Draw images with some examples. Show differences for operations like push/pop, add/remove, etc.arrow_forwardplease convert to C language #include <bits/stdc++.h>using namespace std; typedef long long ll; int main(){ ll t; cout << "Enter number of test cases: "; cin >> t; while (t--) { ll n, m; cout << "Enter number of nodes and edges: "; cin >> n >> m; // declare a vector of stacks of size (n+1) // since index start from 0. stack<int> v1[n + 1]; // declare a vector of queue of size (n+1) // since index start from 0. queue<int> v2[n + 1]; cout << "Enter tree 1: "; for (ll i = 0; i < m; i++) { ll x, y; //enter the elements of its. cin >> x >> y; v1[x].push(y); } cout << "Enter tree 2: "; for (ll i = 0; i < m; i++) { ll x, y; cin >> x >> y; //enter elements of tree 2. v2[x].push(y); } bool flag; //…arrow_forwardQuestion 1 Language: Java Refer to the operations below:Add (10 + 5)Add (4+8)Add (7*2)Add (90 – 3)Print listPrint peekRemove an item from the listPrint list1.1 Implement the operations above into a Queue structure called q1.1.2 Implement the operations above into a Stack structure called s1.arrow_forward
- java language make a stack using linked list and check this stack and chefik, operation on main class means you need 3 files|arrow_forwardjava 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.arrow_forwardComputer Science In c++, make a class that displays a piechart. It should be able to change the number of slices, all while being taken in from a queue. The queue should be within its own class as well, for instance, "push" and "pop", should not be the queue/stack c++ has implemented. Be innovative to it and add color!arrow_forward
- Question 1 (20 marks)Refer to the operations below:Add (10 + 5)Add (4+8)Add (7*2)Add (90 – 3)Print listPrint peekRemove an item from the listPrint list1.1 Implement the operations above into a Queue structure called q1. (10)1.2 Implement the operations above into a Stack structure called s1. (10)Question 2 (20 marks)Create a complete java program called Week_Report. The program must include two array structures, astring array called DaysOfWeek and a double array called Temp_Values. Store in the DaysOfWeek arraythe following values (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). Store in theTemp_Values array the following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for loop structure outputthe values for the two arrays.Day of the Week Temperature ValuesMonday 23.5Tuesday 34.0Wednesday 20.9Thursday 45.7Friday 29.3Saturday 34.5Sunday 32.5arrow_forwardQueue Simulation Create a java program that will simulate Queue operations using 1-D array representation.Each operation is dependent from each other and it's carried out in the next question in a sequential order. Given: A Queue with 10 elements.arrow_forwardCreate a RAPTOR flowchart that implements a queue using two stacks. The queue operations enqueue, dequeue, and empty must be implemented in terms of the push, pop, and empty stack operations. I'd appreciate it if there are screenshots that the flowchart is tested and with output.. thank you in advance!arrow_forward
- Add remain code and explanation of whole code. Given a stack, a function is_consecutive takes a stack as a parameter and thatreturns whether or not the stack contains a sequence of consecutive integersstarting from the bottom of the stack (returning true if it does, returningfalse if it does not). For example:bottom [3, 4, 5, 6, 7] topThen the call of is_consecutive(s) should return true.bottom [3, 4, 6, 7] topThen the call of is_consecutive(s) should return false.bottom [3, 2, 1] topThe function should return false due to reverse order. Note: There are 2 solutions:first_is_consecutive: it uses a single stack as auxiliary storagesecond_is_consecutive: it uses a single queue as auxiliary storage"""import collections def first_is_consecutive(stack): storage_stack = [] for i in range(len(stack)): first_value = stack.pop() if len(stack) == 0: # Case odd number of values in stack return True second_value = stack.pop() if first_value -…arrow_forwardAnswer the following by True or False: NOTE: When the question has been underlined, it requires two (2) answers. The ADT makes use of static array for its queue implementation. The class includes a constructor and destructor. A value must be provided when you initiate a dequeue operation.arrow_forwardUsing this code make function to find level of each node. #include <iostream>#include <stack>using namespace std;struct Node{int data;Node *left, *right;Node(int data){this->data = data;this->left = this->right = nullptr;}};void inorderIterative(Node* root){stack<Node*> stack;Node* curr = root;while (!stack.empty() || curr != nullptr){if (curr != nullptr){stack.push(curr);curr = curr->left;}else {curr = stack.top();stack.pop();cout << curr->data << " ";curr = curr->right;}}}int main(){/* Construct the following tree1/ \/ \2 3/ / \/ / \4 5 6/ \/ \7 8*/Node* root = new Node(1);root->left = new Node(2);root->right = new Node(3);root->left->left = new Node(4);root->right->left = new Node(5);root->right->right = new Node(6);root->right->left->left = new Node(7);root->right->left->right = new Node(8);inorderIterative(root);return 0;} Note: Solve as soon as possiblearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning