Learning materials

Stack and Queue in Java

On this page

Common Characteristics

  • Typical ADTs
  • Linear (one after another)
  • Access data from terminal position(s)

Stack

  • LIFO (Last In, First Out)
  • Behaviors
    • push
    • pop
    • peek
    • isEmpty
  • Implementation
    • linked-list
      • minimal: singly linked-list with a head/first reference variable
    • Compare array and linked-list operations in our ADT Explorer.
    • Array (self study, stack visualization)

Queue

  • FIFO (First In, First Out)
  • Behaviors
    • enqueue
    • dequeue
    • peek
    • isEmpty
  • Implementation
    • linked-list
      • minimal: singly linked-list with a head/first and a tail/last reference variables
      • add at tail and remove at head
    • Compare array and linked-list operations in our ADT Explorer.
    • Array (self study, queue visualization)

Interface and generic

  • Defined as interfaces as they are ADTs
  • Employ generic to support different data types of data