Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
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.
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.”
Data Structures AH Computing. Description and exemplification of the following variable types/data structures: 2-D arrays, records, queues, stacks.
Data Structure Dr. Mohamed Khafagy.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
DATA STRUCTURE & ALGORITHMS
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Data Structures - Stacks. What are data structures? Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey)
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Unit : Overview of Queues.
Data Structures & Algorithms
E.G.M. Petrakisstacks, queues1 Stacks  Stack: restricted variant of list  elements may by inserted or deleted from only one end : LIFO lists  top: the.
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
Data Structures from Cormen, Leiserson, Rivest & Stein.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
Lists CSE1303 Part A Data Structures and Algorithms.
CS 206 Introduction to Computer Science II 10 / 28 / 2009 Instructor: Michael Eckmann.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
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.”
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Stacks and Queues Introduction to Computing Science and Programming I.
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Data Structures Using C++
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Stacks And Queues Chapter 18.
Scis.regis.edu ● CS-362: Data Structures Week 8 Dr. Jesús Borrego 1.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
Advanced Higher Computing Science Stacks Queues and linked lists.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
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.
COSC 2P03 Week 21 Stacks – review A Last-In First-Out (LIFO) structure Basic Operations: –push : insert data item onto top of stack –pop : remove data.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Stack ADT (Abstract Data Type) N …
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Queues.
Arrays.
Chapter 15 Lists Objectives
Stacks and Queues.
Queues Chapter 4.
CSC 172 DATA STRUCTURES.
DATA STRUCTURE QUEUE.
Tonga Institute of Higher Education
Data structures.
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Abstract Data Type Abstract Data Type as a design tool
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Presentation transcript:

Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues

Alford Academy Business Education and Computing2 Lesson Objectives Stack and Queue

Alford Academy Business Education and Computing 3 Stack - Last In First Out (LIFO) A stack can be considered a 1-D array with the following special features:- 1.Items are added to the top of the stack (PUSH) 2.Items are removed from the top of the stack (POP) 3.Items cannot be added to the stack if it is full (STACK OVERFLOW) 4.Items cannot be removed from the stack if it is empty (STACK UNDERFLOW) stackPointer This stack illustrates the following stack operations: 1. PUSH(3) 2. PUSH(2) 3. PUSH(1) 4. PUSH(5)

Alford Academy Business Education and Computing 4 Stack Operations Show the state of an initially empty stack after the following sequence of stack operations. Your diagram should show the position of stackPointer:- PUSH(10) PUSH(12) POP PUSH(17) POP PUSH(100)

Alford Academy Business Education and Computing 5 Stack PUSH and POP algorithms The following algorithms apply to a stack data structure: PUSH a data item onto the stack If stackPointer > maximum then output ‘Stack Overflow’ Else stackPointer = stackPointer + 1 stack(stackPointer) = data item End if POP a data item from the stack If stackPointer < minimum then output ‘Stack Underflow’ Else data item = stack(stackPointer) stackPointer = stackPointer - 1 End if

Alford Academy Business Education and Computing 6 Practice in Using Stack PUSH and POP Do SCHOLAR p124 Q1 and Q2 Implement the program to PUSH and POP a stack in the handout

Alford Academy Business Education and Computing 7 Queue – First In First Out (FIFO) A queue can be considered a 1-D array with the following special features:- 1.Items are added to the rear of the queue 2.Items are removed from the start of the queue 3.Items cannot be added to the queue if it is full (QUEUE FULL) 4.Items cannot be removed from the queue if it is empty (QUEUE EMPTY) rear This queue illustrates the following queue operations: ADDQUEUE(3) ADDQUEUE(2) ADDQUEUE(1) ADDQUEUE(5) start

Alford Academy Business Education and Computing 8 Queue ADD and REMOVE algorithms The following algorithms apply to a queue data structure: ADD a data item onto the queue If (rear = maximum) and (start = 1) Then output ‘Queue Full’ Else rear = rear + 1 queue(rear) = data item End if REMOVE a data item from the queue If (rear = 0) Or (start > rear) then output ‘Queue Empty’ Else data item = queue(start) start = start + 1 End if

Alford Academy Business Education and Computing 9 Practice in Using Queue ADD and REMOVE Implement the program to ADD and REMOVE using a queue in the handout Do SCHOLAR p130 Q5 and Q6 HOMEWORK – Read SCHOLAR Topic 6 (stack and queue). Don’t worry if their algorithms are slightly different from mine. Have all code working with screenshots and printouts of code + test cases