2
Stacks and queues
The concept of introducing and deleting data within a list is summarized
below.
Reference
LIFO
“LIFO” refers to an order in which the
last data entered is the first one removed. Abbreviation for “Last-In-FirstOut.”
●Stacks
A “stack” is a method through which data is introduced to the end of a
list, and the last data added to the list is deleted. Also referred to as a
“LIFO” list.
The basic structure of a stack is shown below.
PUSH (n)
Introduce the data (n)
POP
Delete the last piece of data
PUSH (n)
POP
Deleted in the order of 4→3→2→1
4
3
2
1
Reference
FIFO
“FIFO” refers to an order in which the
first data entered is the first one removed.
Abbreviation for “First-In-First-Out.”
●Queues
A “queue” is a method through which data is introduced to the end of a
list, and the first data added to the list is deleted. Also referred to as a
“FIFO” list.
The basic structure of a queue is shown below.
ENQUEUE (n)
Introduce the data (n)
DEQUEUE
Delete the first piece of data
ENQUEUE (n)
4
3
2
1
DEQUEUE
Deleted in the order of 1→2→3→4
173