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.

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
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Data Structure HKOI training /4/2010 So Pak Yeung.
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.
Stack & Queues COP 3502.
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)
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
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.
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.
 A queue is a waiting line…….  It’s in daily life:-  A line of persons waiting to check out at a supermarket.  A line of persons waiting.
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.
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 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
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.
© 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.
Summary of lectures (1 to 11)
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
Data Structures - Queues
DATA STRUCTURES ACM EXECUTIVE BODY 2k11.  A series of elements of same type  Placed in contiguous memory locations  Can be individually referenced.
Stack and Queue.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Programming Interest Group Tutorial Two Data Structures.
Chapter 16 Stacks & Queues. Objective In this chapter we will learn:  Stacks  Queues  Different implementations (arrays and linked list) of both 
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
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’
Useful Data Structures in C++ and Java. Useful Data Structures in C++ (1) Templates are C++’s mechanism to define abstract objects which can be parameterized.
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.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
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.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
1 Queues Queue API Application: Radix Sort Implementation: Using Deque Using Deque Circular Array Circular Array Priority Queue Priority Queue API Implementation.
CPS Review of Data Structures l We’ve studied concrete data structures/type (CDT)  Vectors Homogeneous aggregates supporting random access  Linked.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
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 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Cpt S 122 – Data Structures Abstract Data Types
Data Structure By Amee Trivedi.
G64ADS Advanced Data Structures
Chapter 12 – Data Structures
Chapter 15 Lists Objectives
Stacks and Queues.
Stack and Queue APURBO DATTA.
Stack and Queue.
CMSC 341 Lecture 5 Stacks, Queues
אחסון (אירגון) מידע DATA DATA DATA Link Link Link … …
Stacks and Queues CSE 373 Data Structures.
CSC 143 Stacks [Chapter 6].
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
CSE 373 Data Structures Lecture 6
Containers: Queue and List
CSE 373 Data Structures Lecture 6
Stacks, Queues, and Deques
Data Structures & Programming
Presentation transcript:

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 at the top of the stack Pop : remove the top element This function does NOT return the top element (because if the stack were empty, the function would be undefined). Top : return the top element (without removing it) IsEmpty : return true is empty, false otherwise

2 Stack Main characteristics : LIFO structure: last in, first out Only the top element may be accessed at any time The only way to access an element in the middle of the stack is by popping all the elements above it.

3 Stack Stacks in the STL: #include There are no iterators (since it is not possible to traverse a stack). stack S; S.push(10); S.push(15); int x = S.top(); if (!S.empty()) S.pop();

4 Queue Data : a collection of homogeneous elements arranged in a sequence. Elements can inserted only at the back and removed only from the front. Operations: Enqueue : insert an element at the back Dequeue : remove an element from the front Front : return the front element IsEmpty : return true if empty, false otherwise.

5 Queue Main characteristics : FIFO structure: first in, first out Only the front element may be accessed at any time The only way to access an element in the middle of the queue is by removing all the elements before it.

6 Queue Implementing our own queue: Idea 1: Use contiguous memory (an array) Make the array circular. Idea 2: Use linked memory Use a node structure to store the data and a pointer to the next node: create a chain of nodes Which end of the list is the front of the queue? The head, since it can be deleted faster than the tail

7 Queue Queues in the STL #include no iterators queue Q; Q.push(10.45); Q.push(-6.78); int s = Q.size(); cout << Q.front() << endl; if (!Q.empty()) Q.pop();