Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Describe the two basic operations on a stack.

Problem 4

Consider the following statements: stackType stack; int x; Suppose that the input is: 14 45 34 23 10 5 -999 Show what is output by the following segment of code: stack.push(5); cin >> x; while (x != -999) { if (x % 2 == 0) { if (!stack.isFullStack()) stack.push(x); } else cout << "x = " << x << endl; cin >> x; } cout << "Stack Elements: "; while (!stack.isEmptyStack()) { cout << " " << stack.top(); stack.pop(); } cout << endl;

Problem 5

Evaluate the following postfix expressions: a. 8 2 + 3 * 16 4 / - = b. 12 25 5 1 / / * 8 7 + - = c. 70 14 4 5 15 3 / * - - / 6 + = d. 3 5 6 * + 13 - 18 2 / + =

Problem 6

Convert the following infix expressions to postfix notations. a. (A + B) * (C + D) - E b. A - (B + C) * D + E / F c. ((A + B) / (C - D) + E) * F - G d. A + B * (C + D) - E / F * G + H

Problem 7

Write the equivalent infix expression for the following postfix expressions. a. A B * C + b. A B + C D - * c. A B – C – D *

Problem 11

Suppose that stack is an object of type 1 inkedstackType \(\langle\text { int }\rangle .\) What is the difference between the statements stack.top () ; and stack.pop();?

Problem 13

Write the definition of the method second that takes as a parameter a stack object and returns the second element of the stack. The original stack remains unchanged.

Problem 14

Consider the following statements: queueType queue; int x, y; Show what is output by the following segment of code: x = 4; y = 5; queue.addQueue(x); queue.addQueue(y); x = queue.front(); queue.deleteQueue(); queue.addQueue(x + 5); queue.addQueue(16); queue.addQueue(x); queue.addQueue(y - 3); cout << "Queue Elements: "; while (!queue.isEmptyQueue()) { cout << queue.front() << " "; queue.deleteQueue(); } cout << endl;

Problem 16

What does the following function do? void mystery(queueType& q) { stackType s; while (!q.isEmptyQueue()) { s.push(q.front()); q.deleteQueue(); } while (!s.isEmptyStack()) { q.addQueue(2 * s.top()); s.pop(); } }

Problem 17

Suppose that queue is a queueType object and the size of the array implementing queue is \(100 .\) Also, suppose that the value of queueFront is 50 and the value of queueRear is 99 a. What are the values of queueFront and queueRear after adding an element to queue? b. What are the values of queueFront and queueRear after removing an element from queue?

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks