Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. A single array A [1...MAXSIZE] is used to implement two stacks. The two stack graw from opposite ends of the array. Variable top 1 and top 2 (top 1 < top 2) point to the location of the topmost element in the each of the stacks. If the space is to be used efficiently, the condition for stack full is
    1. (top1 – MAXSIZE/ 2) and (top 2 = MAXSIZE/2 + 1)
    2. top1 + top 2 = MAXSIZE
    3. (top1 = MAZSIZE/2) or (top 2 = MAXSIZE)
    4. top1 = top 2 – 1
Correct Option: D

Let take MAXSIZE =10

Here the stack will be fuel if both top 1 & top 2 are at the adjacent index values i.e., their difference is 1.
So top 1 = top 2 – 1
Here (d) is correct option.



Your comments will be displayed only after manual approval.