13. Suppose that stack is an object of type linkedStackType<int>. What is the di
ID: 3554597 • Letter: 1
Question
13. Suppose that stack is an object of type linkedStackType<int>. What is the difference
between the statements stack.top(); and stack.pop();?
14. Write the definition of the function template printListReverse that uses a stack to print
a linked list in reverse order. Assume that this function is a member of the class
linkedListType
15. 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.
16. Consider the following statements:
queueType <int> queue;
int num;
What is the 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<<
Explanation / Answer
13. stack.top() indicates the top most element of the stack.
stack.pop() removes the top elemenet from the stack
14. void printReverseList() //assume linked list is inserted into the stack.
{
while(stack.top!=-1)
{
cout<<stack.pop();
}
}
15.
int second(stack.top)
{
return stack[top-1];
}
16.
output
Queue elements: 12 14 12 25
18) this function will push the elements of the queue into the stack, until queue is empty.
add the twice the top (2*top) element of the stack into the queue, until stack is empty
19) a) since queueRear value is 99. no more elements can be added, unless it is circular queue.
queueFront=50.
b) queueFront=51
queueRear=99
20) a) queueFront=99 ; queueRear=26
b) queueFront=0 ; queueRear=26
21)
a) queueFront=25 ; queueRear=76
b) queueFront=26 ; queueRear=76
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.