Stacks, queues and linked lists – pointers step by step

Computer ScienceAlgorithms & Problem SolvingAges 17–18

Loading…

Use with my class ✨ Customize with AI Report a problem

Push and pop on a stack, enqueue and dequeue on linear, circular and priority queues, and insert, delete and search nodes in a linked list, watching the top, front, rear and head pointers and the next links change line by line in Python or pseudocode, with overflow and underflow. Compare static array implementations with dynamic nodes and pointers, including memory use, and try applications: bracket matching, undo/redo, a print queue and the call stack.

Lesson: Abstract data structures: stacks, queues and linked lists; array-based and pointer-based implementations

What it shows

Stacks, queues and linked lists are abstract data structures. A stack is last in, first out: push and pop work at the top. A queue is first in, first out: items join at the rear and leave from the front; a circular queue reuses freed cells with MOD, and a priority queue serves the highest priority first. A linked list stores each value in a node with a pointer to the next node, ending in a null pointer. A static array reserves a fixed block of memory and can overflow, while dynamic nodes grow and shrink but need extra memory for pointers.

How to use

Choose Stack, Queue, Linked list or Applications and an Implementation. Type a Value and press an operation button such as Push, Enqueue or Insert at position; the code runs one line at a time at the chosen Speed. Tick Line by line and press Next line to go slowly, or Finish operation. Watch the pointers, the Memory panel and the Operations log.

Parameters you can change

  • Mode Stack, Queue, Linked list, Applications
  • Implementation Static array, Nodes and pointers (dynamic)
  • Queue type Linear, Circular, Priority
  • Array capacity 3–10 cells
  • Application Bracket matching (stack), Undo / redo (two stacks), Print queue (queue), Call stack
  • Language Python, Pseudocode
  • Run speed 0.5–5 lines/s

Questions to explore

  1. Why can a linear queue be full while cells at the front are empty, and how does a circular queue fix this?
  2. Which pointers change when you insert a node in the middle of a linked list?
  3. How many bytes do six integers need as a static array and as linked nodes in this model?