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

Suppose that stack is an object of type stackType and the value of stack.top - 1 is 2. How many elements are in the stack?

Problem 5

Consider the following statements: stackType stack; int num1, num2; Show what is output by the following segment of code: stack.push(12); stack.push(5); num1 = stack.top() + 3; stack.push(num1 + 5); num2 = stack.top(); stack.push(num1 + num2); num2 = stack.top(); stack.pop(); stack.push(15); num1 = stack.top(); stack.pop(); while (!stack.isEmptyStack()) { cout << stack.top() << " "; stack.pop(); } cout << endl; cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl;

Problem 6

Consider the following statements: stackType stack(50); int num; Suppose that the input is: 31 47 86 39 62 71 15 63 Show what is output by the following segment of code: cin >> num; while (cin) { if (!stack.isFullStack()) { if (num % 2 == 0 || num % 3 == 0) stack.push(num); else if (!stack.isEmptyStack()) { cout << stack.top() << " "; stack.pop(); } else stack.push(num + 3); } cin >> num; } cout << endl; cout << "Stack Elements: "; while (!stack.isEmptyStack()) { cout << " " << stack.top(); stack.pop(); } cout << endl;

Problem 7

Evaluate the following postfix expressions: a. \(1753-* 6+=\) b. \(142 * 8+6 / 5+=\) c. \(15163102++-+8 /=\) d. \(1812--9+255 / \star=\)

Problem 8

Convert the following infix expressions to postfix notations: a. x * (y + z) - ( w + t) b. (x + y) / (z - w) * t c. ((x - y) + (z - w) / t) * u d. x - y / (z + w) * t / u + (v - s)

Problem 9

Write the equivalent infix expressions for the following postfix expressions: a. x y + z * w - b. x y * z / w + c. x y z + * w -

Problem 13

Suppose that stack is an object of type linkedStackType. What is the difference between the statements stack.top(); and stack.pop();?

Problem 16

Consider the following statements: queueType queue; int num; Show what is output by the following segment of code: num = 7; queue.addQueue(6); queue.addQueue(num); num = queue.front(); queue.deleteQueue(); queue.addQueue(num + 5); queue.addQueue(14); queue.addQueue(num - 2); queue.addQueue(25); queue.deleteQueue(); cout << "Queue elements: "; while (!queue.isEmptyQueue()) { cout << queue.front() << " "; queue.deleteQueue(); } cout << endl;

Problem 17

Consider the following statements: linkedStackType stack; linkedQueueType queue; int num; Suppose the input is: 48 35 72 88 92 11 10 15 44 52 67 36 Show what is written by the following segment of code: stack.push(0); queue.addQueue(0); cin >> num; while (cin) { switch (num % 3) { case 0: stack.push(num); break; case 1: queue.addQueue(num); break; case 2: if (!stack.isEmptyStack()) { cout << stack.top() << " "; stack.pop(); } else if (!queue.isEmptyQueue()) { cout << queue.front() << " "; queue.deleteQueue(); } else cout << "Stack and queue are empty." << endl; break; } //end switch cin >> num; } //end while cout << endl; cout << "stack: "; while (!stack.isEmptyStack()) { cout << stack.top() << " "; stack.pop(); } cout << endl; cout << "queue: "; while (!queue.isEmptyQueue()) { cout << queue.front() << " "; queue.deleteQueue(); } cout << endl;

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