Computer Science I / Abstract Data Use
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
  1. The swap preserves the published operations and nothing else.
  2. 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.

Read the lesson: Abstract Data Use →

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