דלג לתוכן

Stacks and queues in fixed lists

English

The exam's way: a fixed list and pointers

  • In Paper 4, a stack or queue is not built with append and pop. The question gives a fixed-size list and integer pointers.
  • The list is made once, full of empty values: StackData = [0] * 5. Its length never changes.
  • A pointer holds an index into that list. Python indexes start at 0, so -1 can mean "no item".
  • Use the exact identifiers and starting values the question gives. Here: TopOfStack = -1 means the stack is empty.

Four snapshots of StackData[0] to StackData[4]: empty with TopOfStack -1; after Push(4) and Push(9) TopOfStack is 1; after Push(7) it is 2; Pop() returns 7 and TopOfStack is 1 again

היכנס או צור חשבון

IGCSE, A-Level & AP