Exercise: Re-implementing Quack Functions
Re-implement push() , qush() and pop() for the array implementation of quacks.
push()
- checks that there is a quack
- checks that the array is not full (this is called quack overflow)
- (unlike the linked-list implementation, where there is no maximum number of elements)
- increments the index top
- places the new data at this position in the array
qush()
- checks that there is a quack
- checks that the array is not full
- increments the index top and moves all elements up
- places the new data at the bottom
pop()
- checks that there is a quack
- checks there is no underflow
- copies the element at top, decrements the value of top
- returns the stored top element
|