Stack and Queue in Java¶
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
Array (self study, 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
Array (self study, visualization)
Interface and generic¶
Defined as interfaces as they are ADTs
Employ generic to support different data types of data