- What is an abstract data type?
- An abstract data type (ADT) is a collection of data and a set of operations on those data. A stack, a queue and a linked list are all ADTs. An ADT says what is stored and what can be done to it. How it is built, for example with arrays, is a separate question.
- What is the difference between a stack and a queue?
- A stack adds and removes items at the same end: PUSH adds an item and POP removes one, so the last item pushed is the first popped. A queue works on a first in, first out basis: data is added at the end and removed from the front, using enqueue and dequeue. Applying push and pop to a queue shows confusion between ADTs.
- How does a linked list insert a node in alphabetic sequence?
- First check for a free node, then search for the correct insertion point. Take the first node on the free list, store the data in it, and change the pointer of the node before so it points to the new node. Set the new node's pointer to the node after it. Data is not moved; only pointers change.
- How do you implement a stack using an array?
- Declare a 1D array with one element for each stack item, and an integer stack pointer. The pointer holds an index into the array, never a data item, and it is initialised to show an empty stack. Push and pop must first check for a full or an empty stack.
- What happens to a value when it is popped from a stack?
- A POP does not erase the value. It stays in memory, but the TopOfStack pointer bypasses it. A PUSH moves the pointer to the new item, and a POP moves it back to the item below. Popping an empty stack causes an error.
- What mistake do students make when a circular queue reaches the end of the array?
- They suggest that the existing queue contents must be moved or removed before new data can be added. In a circular queue the End pointer wraps round to location 0, and items already in the queue never move. Check that the queue is not full before adding an item.