Data Structures & Programming

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Queues and Linked Lists
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Chapter 5.
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
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.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Stacks.
Queues.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Stacks and Linked Lists. Abstract Data Types (ADTs) An ADT is an abstraction of a data structure that specifies – Data stored – Operations on the data.
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Iterators, Lists, and Sequences Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science.
1 Chapter 7 The Linked List as a Data Structure. 2 The List ADT A list is a list of elements. The list of elements consist of the data acted upon by list.
Queue Queue – First In / First Out (FIFO) data structure that supports two operations: push for adding new element at the end of the queue pop for removing.
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
CMSC 341 Deques, Stacks and Queues. 2/20/20062 The Double-Ended Queue ADT A Deque (rhymes with “check”) is a “Double Ended QUEue”. A Deque is a restricted.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Linked lists. Data structures to store a collection of items Data structures to store a collection of items are commonly used Typical operations on such.
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
The List ADT Reading: Sections 3.2, 3.3, 3.5.
Lists1 © 2010 Goodrich, Tamassia. Position ADT  The Position ADT models the notion of place within a data structure where a single object is stored 
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
Unit 2 - Stack and Queue Slides 18 to end. Queue CMPT Anne Lavergne18.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Mark Redekopp David Kempe
Cpt S 122 – Data Structures Abstract Data Types
18 Chapter Stacks and Queues
Iterators and Sequences
Chapter 18: Stacks and Queues.
Double-Ended Queues Chapter 5.
Queues, Deques and Priority Queues
Queues, Deques and Priority Queues
Chapter 19: Stacks and Queues.
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Deques, Stacks and Queues
Queue.
Linked Lists: Implementation of Queue & Deque
Chapter 18: Linked Lists.
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
Doubly Linked List Implementation
Recursive Linked List Operations
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Evaluation of List Implementations
Queues Jyh-Shing Roger Jang (張智星)
CMSC 341 Stacks and Queues 4/17/2019.
C++ STL Stack, Queue, and Deque
Doubly Linked List Implementation
Chapter 3 Lists, Stacks, and Queues
The List Container and Iterators
Stacks and Linked Lists
CMPT 225 Lecture 8 – Queue.
Data Structures & Programming
Data Structures & Programming
Queue, Deque, and Priority Queue Implementations
Presentation transcript:

Data Structures & Programming Double-Ended Queue Golnar Sheikhshab

Double-Ended Queue (dequeue) ADT insertFront(e): Insert a new element e at the beginning insertBack(e): Insert a new element e at the end eraseFront(): Remove the first element; throws error if dequeue is empty eraseBack(): Remove the last element; throws error if dequeue is empty front(): Return the first element; throws error if dequeue is empty back(): Return the last element; throws error if dequeue is empty size(): Return the number of elements empty(): Return true if the deque is empty and false otherwise

Example of Operations

STL dequeu #include <dequeue> using std::deque; // make deque accessible deque<string> myDeque; // a deque of strings insertFront and insertBack are called push_front and push_back eraseFront and eraseBack are called pop_front ant pop_back No method throws exception but they can make the program crash.

Implementing a Deque with a Doubly Linked List

Doubly Linked List ADT (reminder) bool empty() const; // is list empty? const Elem& front() const; // get front element const Elem& back() const; // get back element void addFront(const Elem& e); // add to front of list void addBack(const Elem& e); // add to back of list void removeFront(); // remove from front void removeBack(); // remove from back

Time Complexities

Adapter (Wrapper) Design Pattern An adapter (also called a wrapper) is a data structure, for example, a class in C++, that translates one interface to another.

Reading material Section 5.3 of the textbook