Stacks and Queues - Chapter 3 Flashcards
A blank is an ADT in which items are only inserted on or removed from the top
stack
The stack blank operation inserts an item on the top of the stack.
push
The stack blank operation removes and returns the item at the top of the stack.
pop
A stack is referred to as a blank ADT.
last-in first-out
A stack can be implemented using a blank, blank, or blank.
linked list, an array, or a vector
Inserts x on top of stack
Push(stack, x)
Returns and removes item at top of stack
Pop(stack)
Returns but does not remove item at top of stack
Peek(stack)
Returns true if stack has no items
IsEmpty(stack)
Returns the number of items in the stack
GetLength(stack)
blank and blank operations should not be applied to an empty stack; the resulting behavior may be undefined.
Pop and Peek
A stack is often implemented using a blank, with the list’s head node being the stack’s top.
linked list
A stack is often implemented using a linked list, with the list’s head node being the stack’s top. A blank is performed by creating a new list node, assigning the node’s data with the item, and prepending the node to the list. A blank is performed by assigning a local variable with the head node’s data, removing the head node from the list, and then returning the local variable.
push
pop
A stack can be implemented with an array. Two variables are needed in addition to the array:
allocationSize: an integer for the array’s allocated size.
length: an integer for the stack’s length.
An blank is a stack with no upper limit on length
unbounded stack
An unbounded stack’s blank can increase indefinitely, so the stack’s array allocation size must also be able to increase indefinitely.
length
A blank is a stack with a length that does not exceed a maximum value. The maximum is commonly the initial allocation size
bounded stack
A bounded stack with a length equal to the maximum length is said to be blank.
full
The Stack class implementation that follows uses a Python list. A Python list does not have a blank, so implementing reallocation is not needed. Therefore, implementation is simpler than an implementation with a fixed size array.
fixed size
A blank is an ADT in which items are inserted at the end of the queue and removed from the front of the queue
queue
The queue blank operation inserts an item at the end of the queue.
enqueue
The queue blank operation removes and returns the item at the front of the queue.
dequeue
A queue is referred to as a blank ADT.
first-in first-out
A queue can be implemented using a blank or a blank.
linked list or an array