Purchase Solution

Stacks Problem

Not what you're looking for?

Ask Custom Question

1. Suppose there is a program that reads a word and writes the reverse of the word to to output. For example, the program reads "faced" and writes "decaf". The program uses a stack to reverse the string. Please list all activation of the push and pop methods along with which letter is being pushed or popped at each step if the input word is "rain".

2. Show every stack operation and the state of both the numbers and operations stacks after every push and pop when evaluating the arithmetic expression: (((10 * 9) - 3) * (((8 * 2) + 16))).

3. Given a priority queue, list the order that items would be dequeued given the following set of queue operations. The items in the queue are prioritized by an integer value - higher values have a higher priority. Please show your work. (10 pts)
queue.push("lovelace", 1)
queue.push("knuth", 1)
queue.pop()
queue.push("babbage", 10)
queue.push("church", 7)
queue.push("turing", 8)
queue.pop()
queue.pop()
queue.push("dijkstra", 5)
queue.pop()
queue.pop()
queue.pop().

Purchase this Solution

Solution Summary

The solution solves a stacks problem.

Solution Preview

1. For the input word "rain", the push-pop procedure is below.
push("r");
push("a");
push("i");
push("n");
pop(); // "n" is popup
pop(); // "i" is popup
pop(); // "a" is popup
pop(); // "r" is popup
Finally, we get "niar"

2. We need to use two stacks numbers and operations.
For the expression (((10 * 9) - 3) * (((8 * 2) + 16))), we have the following operations.
operations.push("(");
operations.push("(");
operations.push("(");
numbers.push(10);
operations.push("*");
numbers.push(9);
operations.pop(); // Because it meets ")" and a calculation should start. "*" is popup
numbers.pop(); // 9 is pop up
numbers.pop(); // 10 is pop up
Calculate(10*9) and get 90
operations.pop(); // "(" is popup to match ")"
...

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Networking Questions

This quiz consists of some basic networking questions.

C++ Operators

This quiz tests a student's knowledge about C++ operators.