Computer Science I / Abstract Data Use
Practice question · Sort into groups

A stack ADT is being documented. Sort each statement by whether it belongs in the published interface or is an implementation detail.

Groups: Belongs to the interface · Is an implementation detail

Hints
  1. Ask of each statement: would it still be true if the stack were rebuilt on linked nodes instead?
  2. Anything that survives a change of internal representation is part of the promise; anything that does not is machinery.
Show the answer

Belongs to the interface: pop removes and returns the most recently pushed element, peek returns the top element without removing it

Is an implementation detail: The elements are held in a contiguous array of capacity 64, An integer field records how many elements are currently stored

Why

The interface is what callers may rely on, the behaviour of push, pop and peek, including what happens in the error case. Arrays, capacities, counters and doubling are all machinery that a linked-node implementation would replace entirely, so no caller may depend on them.

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