Practice question · Select all that apply
A team replaces a stack's array implementation with a linked-node one. The published operations behave identically. Select every piece of calling code that keeps working.
Hints
- The swap preserves the published operations and nothing else.
- Two options depend on something the interface never promised.
Show the answer
- A. Code calling pop in an empty-stack error handler
- C. Code that pushes items and pops them in reverse order
- D. Code that calls peek in a loop until size reports zero
Why
Anything built from push, pop, peek and size survives, including the documented empty-stack error. Indexing internal storage and depending on a 64-item ceiling both rest on the array's internals, which the linked version does not have, and being able to make this swap safely is the entire payoff of the abstraction barrier.
Practise Abstract Data Use
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Abstract Data Use
- A stack ADT implemented with a fixed-size array can overflow when pushed too many times; the same ADT over a…
- A library documents a function's behaviour but not its complexity. Callers then write loops assuming it is…
- Order what happens when an object is created and then used.
- Because an ADT's interface says nothing about cost, two correct implementations of the same interface can…
- A stack ADT is being documented. Sort each statement by whether it belongs in the published interface or is…