4.2.3 - FoDS (Stacks) Flashcards
1
Q
What are pointers
A
References to the location of stored data items in stack and queues
2
Q
What type of data structures are stacks, and what does the term used to describe it mean
A
LIFO - Last in first out
meaning that the last item placed in is the first item taken out
3
Q
How many pointers do stacks have and where do they point
A
- 1 which points to the front of the stack
4
Q
What are the 4 key functions of stacks
A
- Push/Add items
- Pop/Remove items
- Peek/Top which returns the value of the top element without removing it
- Testing whether full or empty
5
Q
How does the stack pop work
A
- Check to see that the stack isn’t empty
- If empty report an error and stop
- Copy data item in the location pointed to by stack pointer
- Decrement the stack pointer
6
Q
How does the push function work
A
- Check to see that the stack is not full
- If full report an error and stop
- Otherwise, increment the pointer
- Insert new data into the location pointed to by the pointer
7
Q
What is a peek/top
A
- A function of a tack that returns the value of the top element without removing it