Stack and Queues - DPP 01
Stack and Queues - DPP 01
CSE/IT Batch-Hinglish
Data Structure & Programming
Stacks and Queues DPP-01
[NAT] node;
3. A stack is implemented using array. S represents the Let *head denote the address of the start node
pointer to the top element in the stack. Initially the respectively. Assume, the stack is not empty.
stack contains the elements: a(top), b. Assume Consider the following function that intends to delete
Push(S, i) push an element i into the stack at index S. the topmost element of the stack:
Whenever a Push operation will be performed, it will node * f(node *head)
returns S++ after the push operation. Pop() pops the
{
topmost element and returns the next top index. Top()
is a function that returns the topmost element of the node *p=head; ____________;
stack. Consider the following statements: free(p);
p=NULL;
P: Top(Pop((Pop(Pop((Push(Push(S, c), d)))))))= a
}
Q: Pop(Pop(Pop(Pop(Push(Pop(Push(S, c)), d))))) = a
The missing blank is-
Which of the following statements is/are INVALID? (a) while(p → next!=NULL) p=p→next;
(a) P only (b) Q only
(b) p=p → next;
(c) Both P and Q (d) Neither P nor Q
(c) head=head → next;
(d) None
[MCQ]
4. A single array A[1…MAXSIZE] is used to implement
two stacks. The two stacks grow from opposite ends of
the array. Variables top1 and top2 (topl< top 2) point
to the location of the topmost element in each of the
2
[MCQ] [NAT]
7. A stack is implemented using array of size 4. S 8. Let S be a stack of size n≥1. Starting with the empty
represents the pointer to the top element in the
stack, suppose we push the first 5 natural numbers in
stack. Initially the stack contains the elements-
sequence, and then perform 5 pop operations.
a(top), b. Assume Push(S, i) push an element i into
Assume that Push and Pop operations take 3 seconds
the stack at index S. Whenever a Push operation
will be performed, it will returns S++ after the push each, and 1 seconds elapse between the end of one
operation. Pop() pops the topmost element and such stack operation and the start of the next
returns the next top index. isEmpty() returns TRUE operation. The average stack-life of an element of
if the stack is empty. isFull() returns TRUE if the this stack is __________.
stack is full. Consider the following statements:
P: isFull(Push(Pop(Push(Push(S, c), d))), e))=
TRUE
3
Answer Key
1. (5) 5. (c)
2. (a, b, c) 6. (a, b)
3. (c) 7. (c)
4. (d) 8. (17)
4