Presentation on theme: "Queue Chapter 9 Stacks Last in first out (LIFO)Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top."— Presentation transcript:
Queue Chapter 9
Stacks Last in first out (LIFO)Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Stack Of Cups Add a cup to the stack. bottom top C A B D E F Remove a cup from new stack. A stack is a LIFO list. bottom top C A B D E
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only.
Derive From arrayList when front is left end of list and rear is right end empty() => arrayList::empty() size() => arrayList ::size(0) front() => arrayList::get(0) back() => arrayList ::get(size() – 1) 0123456 abcde frontrear
Railroad car rearrangement A freight train has n railroad cars. Each is to be left at a different station. Assume that the n stations are numbered 1 through n and that the freight train visits these stations in the order n through 1. The railroad cars are labeled by their destination. To facilitate removal of the cars from the train, we must reorder the cars so that they are in the order 1 through n from front to back. When the cars are in this order, the last car is detached at each station. We rearrange the cars at a shunting yard that has an input track, an output track, and k holding tracks between the input and output tracks. In our case, a shunting yard with k=3 holding tracks, H1, H2, H3. The initial order of cars is shown as next page. Draw the configuration of the shunting tracks, the input track, and the output track following each. car move made.
Homework 3 Implement Lee’s wire router Using STL queue Implement Railroad car arrangement Using STL stack and Queue Due date: March 1 st