Spring 2008 Mark Fontenot CSE 2341 - Honors Principles of Computer Science I Note Set 15 1.

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

Stacks, Queues, and Linked Lists
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
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.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
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.
Queue Overview Queue ADT Basic operations of queue
CS Data Structures II Review COSC 2006 April 14, 2017
Stack and Queue COMP171 Fall Stack and Queue / Slide 2 Stack Overview * Stack ADT * Basic operations of stack n Pushing, popping etc. * Implementations.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Stacks and Queues COMP171 Fall Stack and Queue / Slide 2 Stack Overview * Stack ADT * Basic operations of stack n Pushing, popping etc. * Implementations.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Chapter 16 Stack and Queues part2
Objectives of these slides:
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Stacks and Queues Introduction to Computing Science and Programming I.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 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.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Stacks And Queues Chapter 18.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Data Structures – Week #4 Queues. January 12, 2016Borahan Tümer, Ph.D.2 Outline Queues Operations on Queues Array Implementation of Queues Linked List.
CE 221 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
CS 221 Analysis of Algorithms Data Structures. Portions of the following slides are from  Goodrich and Tamassia, Algorithm Design: Foundations, Analysis.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
18 Chapter Stacks and Queues
Chapter 18: Stacks and Queues.
CC 215 Data Structures Queue ADT
Chapter 15 Lists Objectives
Queue data structure.
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
CMSC 341 Lecture 5 Stacks, Queues
Pointers and Linked Lists
Chapter 19: Stacks and Queues.
Queues.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Data Structures – Week #4
Presentation transcript:

Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1

Overview 2 Stacks Queues

The Stack 3 STACK data structure that stores and retrieves items in a last-in-first-out manner only have access to element “on top” of the stack How is this different from a basic array?

Stack 4 Think of a stack of plates in a cafeteria first in last infirst out last out

Applications of Stacks 5 Used during program execution Can use a stack to perform mathematical operations general: useful data structure for any algorithms that work with the last saved element of a series.

2 Types 6 Static Stacks Fixed size Implemented as Arrays Dynamic Stacks ability to grow and shrink as needed. Implemented as Linked lists

Basic Stack Operations 7 push(x) causes a value to be stored or pushed onto the stack Empty Stackpush(5) 5 push(10) 5 10 push(7)

Basic Stack Operations 8 pop(x) retrieves (and hence, removes) a value from the stack pop(x) pop(x)

Basic Stack Operations 9 isFull() boolean function needed with fixed-size stacks prevents stack overflow from trying to push a value on when there is no more room isEmpty() boolean function needed for both fixed and dynamic stacks prevents any errors from the pop operation on an empty stack.

The Queue 10 queue data structure that stores and retrieves items in a first-in-first-out manner Elements are added to the rear and removed from the front

Queue 11 Think of a line of people waiting to check out front rear

Applications of Queue 12 Operating systems use queues to keep track of processes that are executing and in which order they are allowed to use the processor Printing queues Communications

2 Types 13 Static queues Fixed size Implemented as Arrays Dynamic queues ability to grow and shrink as needed. Implemented as Linked lists

Basic Queue Operations 14 enqueue(x) causes a value to be stored in the queue Empty Queue enqueue(5) 5 enqueue(10) 510 enqueue(7) FrontRear Front Rear

Basic Queue Operations 15 dequeue() causes a value to be removed from the queue dequeue() dequeue() 10 7

Problem 16 With static queue Every dequeue operation requires the elements behind it to move “forward” – very expensive Can overcome by allowing both front and rear indices to move but possible to run out of room in the array Over come by using a circular array OR dynamic queue.

DynamicQueue 17 class DynIntQueue { private: struct queueNode { int val; queueNode* next; }; queueNode* front; queueNode* rear; public: //See handout! }; 534 Null Front Rear

Fini 18 ?