Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 7 Ming Li Department of.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

1 Linked lists Sections 3.2, 3.3, 3.5 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors.
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
Stack & Queues COP 3502.
COMPSCI 105 S Principles of Computer Science 13 Stacks.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
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.
Chapter 13 Pointers and Linked Lists. Nodes and Linked Lists Linked list: A sequence of nodes in which each node is linked or connected to the node preceding.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 14 Ming Li Department of.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Stacks.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Topic 15 Implementing and Using Stacks
Priority Queues Briana B. Morrison Adapted from Alan Eugenio Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
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.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 8 Ming Li Department of.
Data Structures Chapter 2 Stacks Andreas Savva. 2 Stacks A stack is a data structure in which all insertions and deletions of entries are made at one.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
1 Stacks – Chapter 3 A stack is a data structure in which all insertions and deletions of entries are made at one end, called the top of the stack. Alternatively,
Main Index Contents 11 Main Index Contents Week 4 – Stacks.
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.
Stacks and Queues Introduction to Computing Science and Programming I.
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.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Queues Queue API Application: Radix Sort Implementation: Using Deque Using Deque Circular Array Circular Array Priority Queue Priority Queue API Implementation.
1 CSC 222: Computer Programming II Spring 2004 Stacks and recursion  stack ADT  push, pop, top, empty, size  vector-based implementation, library 
Stack Data Structure By Marwa M. A. Elfattah. Stack - What A stack is one of the most important non- primitive linear data structure in computer science.
STACK Data Structure
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
Main Index Contents 11 Main Index Contents Stacks Further Stack Examples Further Stack Examples Pushing/Popping a Stack Pushing/Popping a Stack Class StackClass.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Chapter 12 – Data Structures
MEMORY REPRESENTATION OF STACKS
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
CSC 143 Stacks [Chapter 6].
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Jordi Cortadella and Jordi Petit Department of Computer Science
Stacks CS-240 Dick Steflik.
Stack.
Stacks.
Abstract Data Types Stacks CSCI 240
CMPT 225 Lecture 7 – Stack.
Presentation transcript:

Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 7 Ming Li Department of Computer Science California State University, Fresno Fall 2006

Introduction to Data Structure, Fall 2006 Slide- 2 California State University, Fresno Stacks A stack is a sequence of items that are accessible at only one end of the sequence.

Introduction to Data Structure, Fall 2006 Slide- 3 California State University, Fresno Pushing/Popping a Stack Because a pop removes the item last added to the stack, we say that a stack has LIFO (last-in/first-out) ordering.

Introduction to Data Structure, Fall 2006 Slide- 4 California State University, Fresno stack(); Create an empty stack. bool empty(); Check whether the stack is empty. Return true if it is empty and false otherwise. int size() const; Return the number of items on the stack. T& top() const; Return a reference to the value of the item at the top of the stack. Precondition:The stack is not empty. const T& top() const; Constant version of top(). Stack Operations

Introduction to Data Structure, Fall 2006 Slide- 5 California State University, Fresno void pop(); Remove the item from the top of the stack. Precondition:The stack is not empty. Postcondition: Either the stack is empty or the stack has a new topmost item from a previous push. void push(const T& item); Insert the argument item at the top of the stack. Postcondition: The stack has a new item at the top. Stack Operations

Introduction to Data Structure, Fall 2006 Slide- 6 California State University, Fresno Using a Stack to Create a Hex Number

Introduction to Data Structure, Fall 2006 Slide- 7 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 8 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 9 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 10 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 11 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 12 California State University, Fresno Uncoupling Stack Elements

Introduction to Data Structure, Fall 2006 Slide- 13 California State University, Fresno Stack - Copying s.pop(); while(!s.empty()) s.pop(); s.push(a[7]); int i=0; while(i++<7) s.push(a[7-i]);

Introduction to Data Structure, Fall 2006 Slide- 14 California State University, Fresno Stack - Reversal s.pop(); while(!s.empty()) s.pop(); s.push(a[0]); int i=0; while(i++<7) s.push(a[i]);

Introduction to Data Structure, Fall 2006 Slide- 15 California State University, Fresno Stack – Traversal & Search if (s.pop() != 6) s.pop(); while(!s.top() !=6) s.pop();

Introduction to Data Structure, Fall 2006 Slide- 16 California State University, Fresno Stack – Insertion if (s.pop() < 6) { s1.push(s.top()); s.pop(); } while(!s.top() < 6) { s1.push(s.top()); s.pop(); } while(!s.top() < 6) { s1.push(s.top()); s.pop(); } s.push(6); while(!s.top() < 6) { s1.push(s.top()); s.pop(); } s.push(6); while(!s1.empty()) { int x = s1.top(); s.push(x); }

Introduction to Data Structure, Fall 2006 Slide- 17 California State University, Fresno 1.How to access min() with O(1), i.e., constant time? 2.Postfix evaluation 3.Memory management Stack Problem

Introduction to Data Structure, Fall 2006 Slide- 18 California State University, Fresno System Stack for Recursion