Page 1212 - exercise #2 Suppose that stack is an object of type stackType<int>.
ID: 3553762 • Letter: P
Question
Page 1212 - exercise #2
Suppose that stack is an object of type stackType<int>. What is the difference between stack.top and stack.top - 1?
Page 1215 - exercise #12
Explain why, in the linked implementation of a stack, it is not necessary to implement the operation to determine whether the stack is full.
Page 1217 - exercise #18
What does the following function do?
void mystery(queueType<int>& q)
{
stackType<int> s;
while (!q.isEmptyQueue() )
{
s.push(q.front() );
q.deleteQueue();
}
while (!s.isEmptyStack() )
{
q.addQueue(2 * s.top() );
s.pop();
}
}
Page 1218 - exercise #20
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 99 and the value of queueRear is 25.
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?
Page 1218 - exercise #22
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 99 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?
Explanation / Answer
Page 1212 - exercise #2:
The difference between the stack. top and stack. top -1 when an object of type stackType<int>:
Here, index starts from 0.
stack. top -1 represents the top element in the stack and
stack. top represents the size of the stack.
Page 1218 - exercise #20:
An object of queueType class is queue. The maximum size of the array to store the elements into the queue is 100. The value of the queueFront is 99. The value of the queueRear is 25. So the queue is not full. And the queue is a circular queue in the queueType class.
a) When inserting a new element in the circular queue, then the queueRear position will move to its next position (that is 26 here). The new element will be inserted into the queue at queueRear position. There will be no changes in the queueFront position.
Thus the value of the queueFront is 99. The value of the queueRear is 26.
b) When removing an element from the circular queue, the element at the position queueFront will be removed and the position queueFront will move to its next position that is 100. But here the maximum index is 99. So the queueFront position will automatically goes to the first position of the array (that is 0). There will be no changes in the position queueRear.
Thus the value of the queueFront is 0. The value of the queueRear is 25.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.