2.3.2 Algorithms for Main Data Structures Flashcards
Are stacks FIFO or FILO?
FILO
Which function adds an item to a stack?
Push
Which functions removes an element from a stack?
Pop
Which function adds an element to a queue?
Enqueue
Which function removes an element from a queue?
Dequeue
What is the purpose of a back pointer in a queue?
Holds the location of the next available space
Which function returns an item at the front of the queue without removing it?
Peek
What is the purpose of the front pointer in a queue?
Points to space containing the first item
What value is the top pointer initiliased to in a stack?
-1
Give pseudocode for the function adding new elements to a stack.
push(element)
top = top + 1
A[top] = element
Give pseudocode for the function adding new elements to a queue.
enqueue(element):
A[back] = element
back = back + 1
Which function returns the item at the top of a stack without removing it?
Peek