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.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Sample PMT online… Browse 1120/sumII05/PMT/2004_1/ 1120/sumII05/PMT/2004_1/
Lecture 5 Stack Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
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.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Lecture 5 Sept 15 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
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.
Data Structures & Algorithms
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.
Lecture 7 Sept 16 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
Stacks.
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.
Lecture 6 Feb 12 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
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.
TCSS 342, Winter 2005 Lecture Notes
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.
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
The Stack Alexander G. Chefranov CMPE-231 Spring 2012.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
What is a Stack? n Logical (or ADT) level: A stack is an ordered group of homogeneous items in which the removal and addition of items can take place only.
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,
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
SAK 3117 Data Structures Chapter 3: STACKS. Objective To introduce: Stack concepts Stack operations Stack applications CONTENT 3.1 Introduction 3.2 Stack.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
EENG212 Algorithms and Data Structures
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
Data Structures Stack Namiq Sultan 1. Data Structure Definition: Data structures is a study of different methods of organizing the data and possible operations.
Basic Data Structures Stacks. A collection of objects Objects can be inserted into or removed from the collection at one end (top) First-in-last-out.
Data Structures & Algorithms
CHP-3 STACKS.
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.
STACK Data Structure
Stacks & Queues CSC 172 SPRING 2002 LECTURE 4 Agenda  Stack  Definition  Implementation  Analysis  Queue  Definition  Implementation  Analysis.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
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.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
 Chapter 7 introduces the stack data type.  Several example applications of stacks are given in that chapter.  This presentation shows another use called.
Revised based on textbook author’s notes.
MEMORY REPRESENTATION OF STACKS
Stacks.
CSE 373: Data Structures and Algorithms
Data Structures – Week #3
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 and Queues.
Building Java Programs
STACK By:- Rajendra ShakyawalP.G.T. Computer Science KV-No.1, AFS, Tambaram, Chennai.
Stacks and Queues.
Stacks and Queues CLRS, Section 10.1.
CSC 143 Stacks [Chapter 6].
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks and Queues 1.
Abstract Data Type Abstract Data Type as a design tool
Stacks CS-240 Dick Steflik.
Stack.
Data Structures – Week #3
Stacks and Queues.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

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 called the TOP of the stack A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end called the TOP of the stack

What is a Stack A common data structure in computing. A common data structure in computing. Data items are "popped" and "pushed" (retrieved and stored) from the top of the stack. Data items are "popped" and "pushed" (retrieved and stored) from the top of the stack. Stacks normally have a maximum size. It is an error to push items onto a full stack, or pop items off an empty stack. Stacks normally have a maximum size. It is an error to push items onto a full stack, or pop items off an empty stack. LIFO: Last In First Out LIFO: Last In First Out

Stack features ORDERING: maintains order when elements added (new elements are added to the end by default) ORDERING: maintains order when elements added (new elements are added to the end by default) DUPLICATES: yes (allowed) DUPLICATES: yes (allowed) OPERATIONS: OPERATIONS:  add element to end of list ('push')  remove element from end of list ('pop')  isEmpty()  isFull()  Top()

Stacks in computer science the stack is one of the most important data structures in all of computer science the stack is one of the most important data structures in all of computer science  compilers use stacks to evaluate expressions  stacks are great for reversing things, matching up related pairs of things, and backtracking algorithms  stack programming problems:  reverse letters in a string, reverse words in a line, or reverse a list of numbers  examine a file to see if its braces { } and other operators match  convert infix expressions to postfix or prefix

Another implementation of Stack Stacks can be declared by using structures containing two objects Stacks can be declared by using structures containing two objects #define STACKSIZE 100 struct stack { int top; int items[STACKSIZE]; }; struct stack s;

empty() If (s.top==-1)  Stack is empty Else stack is not empty int empty(struct stack *ps) { if (ps->top == -1) return(TRUE);elsereturn(FALSE);} if (empty(&s)) if (empty(&s)) s tack is empty s tack is emptyelse stack is not empty stack is not empty

Push() void push(struct stack *ps, int x) { ps->items[++(ps->top)] = x; { ps->items[++(ps->top)] = x;} void push(struct stack *ps, int x) { if (ps->top==STACKSIZE-1) { if (ps->top==STACKSIZE-1){ cout<< “ stack overflow ” ; exit();} ps->items[++(ps->top)] = x; ps->items[++(ps->top)] = x;return;}

POP( ) int pop(struct stack *ps) { if (empty(ps)) { cout<<stack underflow; exit(1); } return (ps->items[ps->top--]); } To use the pop function, the programmer can declare int x and write x=pop(&s);