ENQUEUE “MATT” MATT FRONTBACK ENQUEUE “ANDREW”

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

Building Java Programs Chapter 14
§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.
Stacks Chapter 11.
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Data Structures and Algorithms (60-254)
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
 Balancing Symbols 3. Applications
Stacks CS 3358 – Data Structures. What is a stack? It is an ordered group of homogeneous items of elements. Elements are added to and removed from 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.
Infix, Postfix, Prefix.
1 Chapter 8 Stacks and Queues. 2 This is a stack of books.
1 Introduction to Stacks What is a Stack? Stack implementation using array. Stack implementation using linked list. Applications of Stacks.
1 CSCD 326 Data Structures I Infix Expressions. 2 Infix Expressions Binary operators appear between operands: W - X / Y - Z Order of evaluation is determined.
1 Stacks Stack Applications Evaluating Postfix Expressions Introduction to Project 2 Reading: L&C Section 3.2,
Chapter 6 Stacks. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2 Chapter Objectives Examine stack processing Define a stack abstract.
Implementing and Using Stacks
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
CS Data Structures Chapter 3 Stacks and Queues.
CS 206 Introduction to Computer Science II 10 / 28 / 2009 Instructor: Michael Eckmann.
Building Java Programs
Evaluation of Expressions
The Stack and Queue Types Lecture 10 Hartmut Kaiser
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 143 Lecture 7 Stacks and Queues reading: "Appendix Q" (see course website) slides created by Marty Stepp and Hélène Martin
Exam 1 –Monday June 25 th –open Book / Open Notes –No Electronic Devices (calculators, laptops, etc) –Room Number: W –Time: 5:30pm to 8:00pm.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
PUSH “MATT” MATT FRONTBACK PUSH “ANDREW” MATT FRONT ANDREW BACK.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Data Structures and Algorithms
CSE 143 Lecture 5 Stacks and Queues slides created by Marty Stepp
Information and Computer Sciences University of Hawaii, Manoa
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
1 Stacks and Queues Starring: IndexOutOfBOundsException Co-Starring: NoSuchElementException.
EC-211 DATA STRUCTURES LECTURE 8. STACK APPLICATIONS Infix, Prefix, and Postfix Expressions Example – Infix: A+B – Prefix: +AB – Postfix: AB+
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
11/24/ CSC Outline  Stacks  Basic operations  Examples of use  Queues  Basic operations  Examples of use  Implementations  Array-based.
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
CHP-3 STACKS.
A stack is a linear, homogeneous, container that stores and dispenses its content in a LIFO manner. LIFO - Last In First Out The last (most recent) item.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
TOWERS OF HANOI. : If n = 1, move disk 1 from pole 'A' to pole 'B'. else: 1.First, move n-1 disks from pole 'A' to pole 'C', using pole 'B' as.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
CE 221 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - II Text: Read Weiss, §3.6 1Izmir University of Economics.
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
Stacks Stack Abstract Data Type (ADT) Stack ADT Interface
Stacks and Queues.
Revised based on textbook author’s notes.
COMPSCI 107 Computer Science Fundamentals
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 4.
Stack application: postponing data usage
PART II STACK APPLICATIONS
Stacks and Queues.
Stacks and Queues.
Stacks and Queues.
Stacks, Queues, and Deques
Infix to Postfix Conversion
Building Java Programs
Stacks and Queues CLRS, Section 10.1.
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Stacks.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks and Queues.
Presentation transcript:

ENQUEUE “MATT”

MATT FRONTBACK

ENQUEUE “ANDREW”

MATT FRONT ANDREW BACK

ENQUEUE “SAMIRA”

SAM IRAMATT FRONT ANDREW BACK

DEQUEUE

SAM IRA FRONT ANDREW BACK

DETERMINE THE OUTPUT FROM THE FOLLOWING: Queue myQueue = new Queue(); for (int i = 0; i < 10; i++) myQueue.enqueue (new Integer (i * i)); while (!myQueue.isEmpty( )) gui.println (myQueue.dequeue( ));

A SYSTEM IS A COLLECTION OF INTERACTING PARTS.

A MODEL IS A SIMPLIFICATION OF A SYSTEM. THE PURPOSE OF BUILDING A MODEL IS TO STUDY THE UNDERLYING SYSTEM.

STACKS

DETERMINE THE OUTPUT FROM THE FOLLOWING: Stack myStack = new Stack( ); for (int i = 0; i < 10; i++) myStack.push (new Integer (i * i)); while (!myStack.isEmpty( )) gui.println (myStack.pop( ));

METHOD DESCRIPTIONS FOR THE Stack CLASS

STACK APPLICATION 1 HOW COMPILERS IMPLEMENT RECURSION

THERE IS A RUN-TIME STACK TO HANDLE THESE ACTIVATION RECORDS. PUSH: WHEN METHOD IS CALLED POP: WHEN EXECUTION OF METHOD IS COMPLETED

AN ACTIVATION RECORD IS SIMILAR TO AN EXECUTION FRAME, EXCEPT THAT AN ACTIVATION RECORD HAS VARIABLES ONLY, NO CODE. YOU CAN REPLACE RECURSION WITH ITERATION BY CREATING YOUR OWN STACK.

// Precondition: n is a non-negative integer. Otherwise, // IllegalArgumentException will be thrown. // Postcondition: The binary equivalent of n has been printed. // The worstTime (n) is O (log n). public void writeBinary (int n) { Stack myStack = new Stack( ); if (n < 0) throw new IllegalArgumentException( ); myStack.push (new Integer (n % 2)); while (n > 1) { n /= 2; myStack.push (new Integer (n % 2)); } // pushing while (!myStack.isEmpty( )) gui.print (myStack.pop( )); gui.println ("\n\n"); } // method writeBinary

STACK APPLICATION 2 CONVERTING FROM INFIX TO POSTFIX

IN INFIX NOTATION, AN OPERATOR IS PLACED BETWEEN ITS OPERANDS. a + b c – d + (e * f – g * h) / i

OLD COMPILERS: INFIX MACHINE LANGUAGE THIS GETS MESSY BECAUSE OF PARENTHESES. NEWER COMPILERS: INFIX POSTFIX MACHINE LANGUAGE

IN POSTFIX NOTATION, AN OPERATOR IS PLACED IMMEDIATELY AFTER ITS OPERANDS. INFIXPOSTFIX a + bab+ a + b * cabc*+ a * b + cab*c+ (a + b) * cab+c*

PARENTHESES ARE NOT NEEDED, AND NOT USED, IN POSTFIX.

LET’S CONVERT AN INFIX STRING TO A POSTFIX STRING. x – y * z

POSTFIX PRESERVES THE ORDER OF OPERANDS, SO AN OPERAND CAN BE APPENDED TO POSTFIX AS SOON AS THAT OPERAND IS ENCOUNTERED IN INFIX.

INFIXPOSTFIX x – y * z x

INFIXPOSTFIX x – y * z x THE OPERANDS FOR ‘-’ ARE NOT YET IN POSTFIX, SO ‘-’ MUST BE TEMPORARILY SAVED SOMEWHERE.

INFIXPOSTFIX x – y * z xy

INFIXPOSTFIX x – y * z xy THE OPERANDS FOR ‘*’ ARE NOT YET IN POSTFIX, SO ‘*’ MUST BE TEMPORARILY SAVED SOMEWHERE, AND RESTORED BEFORE ‘-’.

INFIXPOSTFIX x – y * z xyz

INFIXPOSTFIX x – y * z xyz* –

SUPPOSE, INSTEAD, WE STARTED WITH x*y-z. AFTER MOVING ‘x’ TO POSTFIX, ‘*’ IS TEMPORARILY SAVED, AND THEN ‘y’ IS APPENDED TO POSTFIX. WHAT HAPPENS WHEN ‘-’ IS ACCESSED? INFIXPOSTFIX x * y – z xy

THE TEMPORARY STORAGE FACILITY IS A STACK. HERE IS THE STRATEGY FOR MAINTAINING THE STACK:

INFIX GREATER, PUSH

CONVERT FROM INFIX TO POSTFIX: INFIXPOSTFIX a + b * c / d - e

INFIXPOSTFIX a + b * c / d – e abc*d/+e – - / * + OPERATOR STACK

CONVERT TO POSTFIX: x * (y + z)

TOKENS