Chapter 3 Stacks & Queues
The postfix expression 2 4 6 * + 15 - 21 7 / + = evaluates to ________.
14
The postfix expressions 5 6 + 4 * 10 5 / - = evaluates to ________.
42
What is the output of the following code? queueType<int> queue; int x, y; x = 2; y = 6; queue.addQueue(x); queue.addQueue(y); x = queue.front( ); queue.deleteQueue( ); queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); while (!queue,isEmptyQueue( ) ) { cout << queue.front( ) << " "; queue.deleteQueue( ); } cout << endl;
6 4 2 3
If you try to add a new item to a full stack, the resulting conditions is called an outflow.
False
In the linked implementation of stacks, the memory to store the stack elements is allocated statically.
False
Postfix notation requires the use of parenthesis to enforce operator precedence.
False
The bottom element of the stack is the last element added to the stack.
False
The expression a + b is the same in both infix notation and postfix notation.
False
A stack is a(n) _______ data structure.
LIFO
A queue is a First In First Out data structure.
True
The default constructor for the linked implementation of a stack initializes the stack to an empty state when a stack object is declared.
True
The infix expression (a + b) * (c - d / e) + f is equivalent to the postfix expression ab+ cde /-* f+
True
The following expression (a - b) * (c + d) is equivalent to which of the following postfix expression?
ab- cd +*
A queue is a data structure in which the elements are ________.
added to the rear and deleted from the front
A stack can be implemented as either a(n) _______ or a linked structure.
array
The postfix expression 3 5 + 2 ; 6 - = will generate an error, because it ______.
contains an illegal operator
In evaluating a postfix expression, when the end of expression is encountered, how many elements must the stack contain so that no error is generated?
one
You can perform the add operation, called _____, to add an element onto the stack.
push
A(n)_____ is a list of homogeneous elements in which the addition and deletion of elements occurs only at one end.
stack
The postfix expression 14 2 5 + = will generate an error, because ______.
there will be too many elements in the stack when the equal sign is encountered
The _____ element of the stack is the last element added to the stack.
top
The addition and deletion of elements of a stack occurs only at the ______ of the stack.
top
What is the output of the following code? queueType<int> queue; int x, y; x = 2; y = 3; queue.addQueue(x); queue.addQueue(y); x = queue.front( ); queue.deleteQueue( ); queue.addQueue(x + 2); queue.addQueue(x); queue.addQueue(y - 3); y = queue.front( ); queue.deleteQueue( ); cout << "x = " << x << endl; cout << "y = " << y << endl;
x = 2; y = 3;
What is the output of the following code? stackType<int> stack; int x, y; x = 4; x = 2; stack.push(6); stack.push(x); stack.push(x + 1); y = stack.top( ); stack.pop( ); stack.push(x + y); x = stack.top( ); stack.pop( ); cout << "x = " << x << endl;
x = 9
When a stack is implemented as an array, the array is empty if the value of a stackTop is ______.
zero