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.

Slides:



Advertisements
Similar presentations
1 Linked lists Sections 3.2, 3.3, 3.5 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors.
Advertisements

Queues. Queue Definition Ordered list with property: All insertions take place at one end (tail) All insertions take place at one end (tail) All deletions.
Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can be instantiated.
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.
Queues CSE, POSTECH 2 2 Queues Like a stack, special kind of linear list One end is called front Other end is called rear Additions (insertions or enqueue)
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
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.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Chapter 3 1. Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Data Structures & Algorithms
Stacks.
Lecture 11 Sept 26, 2011 Goals convert from infix to postfix.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
 Chapter 8 introduces the queue data type.  Several example applications of queues are given in that chapter.  This presentation describes the queue.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Stacks CSE, POSTECH. 2 2 Stacks Linear list One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Containers Overview and Class Vector
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
Stacks Chapter 8. Objectives In this chapter, you will: Learn about stacks Examine various stack operations Learn how to implement a stack as an array.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Applications of Stacks and Queues Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
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. FIFO.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
1 Chapter 6 Queues. 2 Topics FIFO (first0in-first0out) structure Implementations: formula-based and linked classes Applications: –railroad-switching problem.
COP 3530 Discussion Session #6 Yilin Shen. Outline Chapter 7 o Q35p 250 o Q39p 265 Chapter 8 o Problem 8.5.3: Rearranging Railroad carsp 289 o Problem.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks Linear list. One end is called top. Other end is called bottom. Additions to and removals from the top end only.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
1 Chapter 5 Stacks. 2 Topics LIFO (last-in-first-out) structure Implementations –Use class LinearList or Chain –from scratch Applications –parentheses.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Reminder: Course Policy
18 Chapter Stacks and Queues
Chapter 18: Stacks and Queues.
Stacks Stacks.
Stacks Linear list. One end is called top. Other end is called bottom.
Chapter 15 Lists Objectives
Homework 4 questions???.
Stacks.
Stacks and Queues CMSC 202.
Stacks Stack: restricted variant of list
The Class chain.
Chapter 19: Stacks and Queues.
Stacks template<class T> class stack { public:
Stacks template<class T> class stack { public:
Queues Linear list. One end is called front. Other end is called rear.
Stacks template<class T> class stack { public:
پشته ها و صف ها.
Visit for more Learning Resources
CE 221 Data Structures and Algorithms
The Class chain.
Using a Queue Chapter 8 introduces the queue data type.
Stacks template<class T> class stack { public:
Using a Queue Chapter 8 introduces the queue data type.
Queues Linear list. One end is called front. Other end is called rear.
Abstract Data Types Stacks CSCI 240
Data Structures & Programming
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.

Bus Stop Queue Bus Stop front rear

Bus Stop Queue Bus Stop front rear

Bus Stop Queue Bus Stop front rear

Bus Stop Queue Bus Stop front rear

The Abstract Class queue template class queue { public: virtual ~queue() {} virtual bool empty() const = 0; virtual int size() const = 0; virtual T& front() = 0; virtual T& back() = 0; virtual void pop() = 0; virtual void push(const T& theElement) = 0; };

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) abcde frontrear

Derive From arrayList pop() => erase(0) push(theElement) => insert(size(), theElement) abcde frontrear

Derive From extendedChain abcde NULL firstNode lastNode frontrear  when front is left end of list and rear is right end empty() => extendedChain::empty() size() => extendedChain::size()

Derive From ExtendedChain abcde NULL firstNode lastNode frontrear front() => get (0) back() => getLast() … new method

Derive From ExtendedChain abcde NULL firstNode lastNode frontrear push(theElement) => push_back(theElement) pop() => erase(0)

Derive From extendedChain edcba NULL firstNode lastNode rearfront  when front is right end of list and rear is left end empty() => extendedChain::empty() size() => extendedChain::size()

Derive From extendedChain abcde NULL firstNode lastNode rearfront front() => getLast() back() => get(0)

Derive From extendedChain abcde NULL firstNode lastNode rearfront push(theElement) => insert(0, theElement) pop() => erase(size() – 1)

Implement Queue Queue.h derivedArrayQueue.h derivedLinkedQueue.h arrayQueue.h linkedQueue.h

Queue in C++

Double ended queue

Applications

Lee’s Wire Router start pin end pin Blue squares are blocked squares. Orange squares are available to route a wire. Label all reachable squares 1 unit from start.

Lee’s Wire Router start pin end pin Label all reachable squares 1 unit from start.

Lee’s Wire Router start pin end pin Label all reachable unlabeled squares 2 units from start. 11

Lee’s Wire Router start pin end pin Label all reachable unlabeled squares 3 units from start

Lee’s Wire Router start pin end pin Label all reachable unlabeled squares 4 units from start

Lee’s Wire Router start pin end pin Label all reachable unlabeled squares 5 units from start

Lee’s Wire Router start pin end pin Label all reachable unlabeled squares 6 units from start

Lee’s Wire Router start pin end pin End pin reached. Traceback

Lee’s Wire Router start pin end pin 4 End pin reached. Traceback

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