{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

The removefromhead applied programming applied

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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++ We programs. programs. So the only addition to allow our LinkedList So LinkedList ADT to operate as a stack (as well as a queue) is ADT the push function. the It's called a stack. It's stack The pop is the queue's RemoveFromHead(). The RemoveFromHead Applied Programming Applied Programming The last of the list-oriented structures is the oriented priority queue. priority An aside. The simplest implementation of a stack is to store The the items in an array. the Push adds item in next unoccupied entry in the Push array. array. It is, in fact, a combination of a queue and a It linked list. linked Removals are as for a queue - off the top. Removals Additions are as for an ordered list – iitems go into tems Additions 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 One queue is that the key (or priority) may change while an item is in the list. while This will require items to move within the list. At the present, this would mean finding new At locations in the list for changed priority items. locations We'll see later a better storage method. Applied Programming Applied Programming Can we use lists to improve on our searching and Can sorting algorithms? sorting Sure can. Hashing can use lists connected to each hash Hashing code, so that colliding key values result in more than one item being stored at a hash position. than Only a linear search through the list is then Only needed – keep lists short. Applied Programming If hashing is an O(1) searching method, is there If an O(n) sorting method? O(n We have ten bins (lists) labelled 0 to 9. Yes. It's called radix sort. Yes. radix Pass one involves placing the data into the bin Pass corresponding to the least significant digit. corresponding We'll need the sort key to be an integer. So any non-iinte...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online