Stacks and Queues Flashcards
Stack
a data structure that mimics a list where items are added and removed from the top.
Pointer
will be used to store the address of the top of the stack
What 4 things are stacks used for?
Holding temporary instructions
For holding during an interrupt
Function/Subroutine Calls
Recursive algorithms hold previous results
Stack underflow
When there is nothing to pop out of the stack
Stack overflow
When you try pushing too much onto a stack that is already full
Queue
a data structure that mimics a list where items are added to the rear and removed from the front. It operates using a First In First Out (FIFO) Model
Start pointer
Stores the address of the front of the queue
Rear Pointer
Stores the address of the rear of the queue
Linked List
a dynamic data structure that store item in nodes
Node
Part of a linked list that has a pointer which points to the address of the next node
What do you do to add a new node at the end of a linked list?
Set the pointer of the last node to the new node.
What do you do to insert a new node between existing nodes?
Pointer of previous node is amended to point to new node, and the new nodes pointer points to the next node in list
What do you do to delete a node from a linked list?
Pointer of previous node before deleted item will change to point to the next item in the list
Traversing lists
Each node is visited and the pointer followed to the address of the next node
Single (linked list)
Nodes have a data item as well as a pointer to the next field, the last node contains a NULL pointer