Unformatted text preview: m to top of the stack
push That is first in/first out, or FIFO.
Another data structure is LIFO, or last in/first out. pop – remove item from the top
pop W e use this structure all the time in C++
programs. So the only addition to allow our LinkedList
ADT to operate as a stack (as well as a queue) is
the push function.
the It's called a stack.
stack The pop is the queue's RemoveFromHead().
Applied Programming Applied Programming The last of the list-oriented structures is the
priority An aside.
The simplest implementation of a stack is to store
the items in an array.
Push adds item in next unoccupied entry in the
array. It is, in fact, a combination of a queue and a
Removals are as for a queue - off the top.
Additions are as for an ordered list – iitems go into
the list according to some key value.
the Pop removes last occupied entry.
We do need to know how big the stack has to be.
Applied Programming One of the special considerations in the priority
queue is that the key (or priority) may change
while an item is in the list.
This will require items to move within the list.
At the present, this would mean finding new
locations in the list for changed priority items.
We'll see later a better storage method.
Applied Programming Applied Programming Can we use lists to improve on our searching and
Hashing can use lists connected to each hash
code, so that colliding key values result in more
than one item being stored at a hash position.
Only a linear search through the list is then
needed – keep lists short.
Applied Programming If hashing is an O(1) searching method, is there
an O(n) sorting method?
O(n We have ten bins (lists) labelled 0 to 9. Yes. It's called radix sort.
radix Pass one involves placing the data into the bin
corresponding to the least significant digit.
corresponding We'll need the sort key to be an integer.
So any non-iinte...
View Full Document
- Spring '14
- Computer Science, curr