This preview shows page 1. Sign up to view the full content.
Unformatted text preview: be in reverse order. Let’s assume that the insert puts the item at the begin-ning of the list and uses a stack to print a list in reverse order. That is, if the list is in reverse order and we print it in reverse order, the list should be ordered appropriately. Right? Let’s try it. If items 90, 65, 80, 95, 75, 60 are entered into a linked implementation of an unordered list with each item going at the front of the list, the list would look like the one in Figure 9.5. The first item is accessed and put onto the stack, the second item is accessed and put on the stack, and so on. When the last item has been added to the stack, the contents of the stack look like this: Top of stack Bottom of the stack 60 75 95 80 65 90 Print list While ( more items ) Get an item Push item While ( NOT IsEmpty ) Pop item Print item...
View Full Document
This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.
- Fall '10