Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

Similar documents
DATA STRUCTURE - STACK

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1

HW3: Programming with stacks

Data Structures Using C++ 2E. Chapter 5 Linked Lists

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

Outline. The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack. Stacks 2

Data Structures and Algorithms Stacks and Queues

Analysis of a Search Algorithm

Stacks. Linear data structures

Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

DATA STRUCTURE - QUEUE

St S a t ck a ck nd Qu Q eue 1

Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

Introduction to Stacks

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Data Structures and Algorithms V Otávio Braga

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

CompSci-61B, Data Structures Final Exam

7.1 Our Current Model

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

Chapter 3: Restricted Structures Page 1

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

Universidad Carlos III de Madrid

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

DATA STRUCTURES USING C

Common Data Structures

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Linked Lists Linked Lists, Queues, and Stacks

CSE 143, Winter 2013 Programming Assignment #2: HTML Validator Due Thursday, July 10, 2014, 11:30 PM

Cpt S 223. School of EECS, WSU

Data Structures in the Java API

Lecture Notes on Stacks & Queues

Bottom-Up Parsing. An Introductory Example

Module 2 Stacks and Queues: Abstract Data Types

Stacks. Data Structures and Data Types. Collections

14 Stacks, Queues, And Linked Lists

Lecture 12: Abstract data types

Data Structures and Algorithms

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Stacks and queues. Algorithms and Data Structures, Fall Rasmus Pagh. Based on slides by Kevin Wayne, Princeton

Practical Session 4 Java Collections

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

PES Institute of Technology-BSC QUESTION BANK

STACKS,QUEUES, AND LINKED LISTS

1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: Data Structures

Data Structures In Java

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

Algorithms and Data Structures

Programming with Data Structures

Code Refactoring and Defects

Data Structures and Algorithms Lists

Abstract Data Types. Chapter 2

Data Structure [Question Bank]

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

CmpSci 187: Programming with Data Structures Spring 2015

Sequential Data Structures

HiDb: A Haskell In-Memory Relational Database

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

C++ INTERVIEW QUESTIONS

Algorithms and Data Structures

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

Object-Oriented Programming

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

Basic Data Structures and Algorithms

Cours de C++ Utilisations des conteneurs

Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1

Chapter Objectives. Chapter 7. Stacks. Various Types of Stacks LIFO. Empty Stack. Stacks

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

PROBLEMS (Cap. 4 - Istruzioni macchina)

Thread Synchronization and the Java Monitor

Basic Parsing Algorithms Chart Parsing

Stack Allocation. Run-Time Data Structures. Static Structures

Recursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Start Oracle Insurance Policy Administration. Activity Processing. Version

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Data Structures, Practice Homework 2, with Solutions (not to be handed in)

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

Lecture 2: Data Structures Steven Skiena. skiena

Java Collection Framework hierarchy. What is Data Structure? Chapter 20 Lists, Stacks, Queues, and Priority Queues

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University

Android Application Development Course Program

Chapter 8: Bags and Sets

Shipbeat Magento Module. Installation and user guide

Glossary of Object Oriented Terms

Data Structures and Data Manipulation

Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Transcription:

ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting in line, but... Have already seen one important stack Call stack: tracks local variables, parameters, return locations Implicitly part of language, does not need explicit ADT Useful for reversing things Push each thing on the stack in order Popping the stack gives elements in reverse order Don t overcomplicate simple reversals though! Useful for nested matching Example: nested parenthesis ( 4 + (3 * 2) - (8 * 9) + 1) Also, html, xml, etc.. More generally, useful for parsing Analyzing an input string to determine meaning According to a grammar (fixed formal set of rules) 6

Use a Stack, it starts out empty... Start reading the input (just strings) push it on the stack 7 8 push it on the stack push it on the stack 9 10 All the tags on the stack apply to any (non-tag) we encounter Encounter a close tag: pop the stack (remove its top) 11 12

Encounter a close tag: pop the stack (remove its top) <i> <b> 13 14 Stack Example: Undo Many editing tools have Undo feature Also works with a stack Push each change (or document state) onto a stack Undo reverts the last change (LIFO) Redo functionality: put undone changes onto another stack 15 16 17 18

bool isempty() const; //check empty 19 20 bool isempty() const; //check empty int size() const; //how many? }; virtual void push(t item) = 0; virtual T pop() = 0; virtual T & peek() = 0; virtual bool isempty() const = 0; virtual int size() const = 0; }; ADT: so all methods abstract (pure virtual) 21 22 Push: increment TOS, store data there tos = -1 tos = 01-1 A B 23 24

Peek : Examine data[tos] Pop: result is data[tos] decrement tos tos = 1 A B tos = 10 A B 25 26 tos = 09 A BC D E F G H I J K If we push a bunch of elements... tos = 9 Our stack is full Similar options to Queue: Error: rely on users not to push or Grow: resize array A BC D E F G H I J K Growing is easier than Queue: C: realloc the array C++: new array, copy elements (or use a vector) 27 28 Wrap Up: Stacks Stacks: Last In First Out Example uses Parsing/matching balanced items Undo/redo stacks Could use array implementation... Or we could use a Linked List Next segment 29