Q.Write a user-defined function Pop(Book B[], int &T), which pops the details of a Book, from the static stack of Book B, at the location T (representing the Top end of the stack), where every Book of the stack is represented by the following structure: struct Book { int Bno; char Bname[20]; };
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a): pop a static array stack — display B[T] then T-- (T by reference). Part (b): push into a dynamic linked stack — new node, nb->Link = Top, then Top = nb.
Both alternatives revolve around the same LIFO idea; the difference is how memory is held and how the "top" is tracked.
Part (a)
Here the stack is an array Book B[] with an integer T (passed by reference, int &T) marking the index of the topmost element. Popping means removing the element at index T, so we first guard against an empty stack, display the top book, and then decrement T. The array data is not physically erased — the logical top simply moves down.
struct Book { int Bno; char Bname[20]; };
void Pop(Book B[], int &T) {
if (T < 0) { // underflow guard (T == -1 means empty)
cout << "Stack Underflow" << endl;
} else {
cout << "Popped Book Number: " << B[T].Bno << endl;
cout << "Popped Book Name : " << B[T].Bname << endl;
T--; // new top is one below
}
}
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.