Stack and Queue Author : Srinadh Gunnam.

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
Data Structure HKOI training /4/2010 So Pak Yeung.
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
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.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Data Structures: Lists i206 Fall 2010 John Chuang Some slides adapted from Glenn Brookshear, Brian Hayes, or Marti Hearst.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Data Structures from Cormen, Leiserson, Rivest & Stein.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
Objectives of these slides:
Stack and Queue.
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000.
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 Data Structures - Part II CS215 Lecture #8. Stacks  Last-In-First-Out (LIFO)  Stacks are often used in programming when data will need to be used.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
UNIVERSAL COLLEGE OF ENGG. AND TECH. 3 RD IT. QUEUE ( data structure)
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Review Array Array Elements Accessing array elements
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 12 – Data Structures
COSC160: Data Structures: Lists and Queues
September 29 – Stacks and queues
Practical Office 2007 Chapter 10
Chapter 15 Lists Objectives
Stacks and Queues CMSC 202.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Introduction to Data Structure
HW-6 Deadline Extended to April 27th
Principles of Computing – UFCFA3-30-1
Pointers and Linked Lists
Lecture 21 Stacks and Queues Richard Gesick.
Information of the LO Subject: Information Theory Domain: Algorithms
Doubly linked lists Idea: same as singly linked list, but each node also points to the previous: Can optionally also have a pointer to the tail, so we.
Stacks, Queues, and Deques
Introduction to Data Structures
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Abstract Data Type Abstract Data Type as a design tool
Sorted Linked List A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains.
Visit for more Learning Resources
Abstract Data Type (ADT)
Using a Queue Chapter 8 introduces the queue data type.
Welcome 1 This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Using a Queue Chapter 8 introduces the queue data type.
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Stacks, Queues, and Deques
Lecture 9: Stack and Queue
Presentation transcript:

Stack and Queue Author : Srinadh Gunnam

Stack -- Introduction Last In First Out Data structure. The element that can be removed is the one that is most recently inserted. Only top most element is accessible. Stack pointer always points to the top element that can be removed. Ex : Plates arranged on top of one another.

Stack – Operations Push :- Inserts the given item at the top of the stack Pop :- Removes the top most element. Over flow : Error, when tried to push into an fully filled stack Under flow : Error, when tried to pop from an empty stack 3

Queue -- Introduction First In First Out Data structure. The elements are removed in the order of their insertion. Head always points to the front of the queue, from where elements can be removed. Tail always points to the end of the queue , where a new element can be inserted . Ex : typical queues in reservation centres and cinema halls .

Queue – Operations Enqueue :- inserts the given item at the location pointed by tail Dequeue :- removes the element, which is pointed by head . Over flow : error, when tried to Enqueue into an fully filled queue (only in case of limited capacity queues) Under flow : error, when tried to Dequeue from an empty queue. 5

Animation Details The animations of stack and queue are shown side by side. User can select the operations he is interested in, by using the respective buttons. The capacity of stack and queue is taken to be limited in the present example . The user can also be given the option to enter the capacity of the stack or queue. (to provide more interactivity.)

Animation Initially the animation will be as shown in the next slide , with empty stack and queue (the capacity is taken to be 5). Stack pointer S points to bottom of the first element. In queue, Head H points to bottom of first element (as there are no elements to be removed) Tail T points to first element where the given item can be inserted.

Animation Initially the scenario as shown bellow.

Animation User can insert the elements using the Push button in case of stack and Enqueue button in case of queue. He can specify the value in the text box provided. A sample example when elements 1, 2 and 3 are inserted in the order is shown in the next slide. Here the stack pointer moves with the top most element location. Tail T always points to next free location in queue. Head H points to the current first element or to the starting location of the queue. (Generally it wont change till all the elements are dequeued).

Animation After insertion

Animation User can also remove the elements by using button Pop in case of stack and Dequeue in case of queue. A sample example when one element is removed from the last scenario is shown in next slide. In case of stack, the element at the location pointed by the stack pointer is removed and pointer is updated to the next top element. In case of queue, the element at the location pointed by Head is removed and all the elements are moved by one position towards head. Tail will be updated to next free location.

Animation

Boundary conditions When user tries to insert a new element in a fully filled stack or queue, “STCK OVER-FLOW “ or “QUEUE FULL “ should be displayed without insertion. When the last element is also deleted i.e. stack or queue becomes empty, stack pointer should point to bottom of first element. Head to bottom of first element and tail to first location . When either is empty and user tries to remove an element , the error message “STACK UNDER-FLOW “ or “QUEUE EMPTY” should be displayed .

Interactivity The user can observe the operations of stack and queue by using the respective buttons. Initially the user can be asked to enter the size of the stack or queue and then they can be created accordingly with the specified size. All the concepts (Introduction and operations) can be shown on one side of animation for user reference.

Questions If the characters 'D', 'C', 'B', 'A' are placed in a stack (in that order), and then removed one at a time, in what order will they be removed? ( ABCD)‏ If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? ( DCBA)‏ One example of stack operation : CDs in a case One example of queue operation : Luggage checking in airports etc.

Useful links http://www.cmpe.boun.edu.tr/~akin/cmpe223/chap2.htm http://www2.roguewave.com/support/docs/hppdocs/stdug/10.html www.wikipedia.com

Thank You Any suggestions ?