Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.

Slides:



Advertisements
Similar presentations
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Advertisements

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.
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.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
Stacks, Queues, and Deques
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.
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.
S. Barua – CPSC 240 CHAPTER 10 THE STACK Stack - A LIFO (last-in first-out) storage structure. The.
Data Structures from Cormen, Leiserson, Rivest & Stein.
Arrays and Other Data Structures 4 Introduction to Arrays 4 Bounds and Subscripts 4 Integer Arrays 4 Floating Point Number Arrays 4 Lists (Linked) 4 Stacks.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
Object Oriented Data Structures
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
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,
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.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
 STACK STACK  BASIC STACK OPERATIONS BASIC STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  EVALUATING A POSTFIX EXPRESSION.
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
FIST, Multi Media University Lecture 5 Stack (Array Implementation) Queue (Array Implementation )
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
Object-Oriented Programming Simple Stack Implementation.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
Data Structures & Algorithms
 STACK STACK  STACK OPERATIONS STACK OPERATIONS  PUSH ALGORITHM PUSH ALGORITHM  POP ALGORITHM POP ALGORITHM  USES OF STACK USES OF STACK  THE TOWER.
Stacks Nour El-Kadri CSI Stacks Software stacks are abstract data types (structures) similar to physical stacks, Plates Trays Books PEZ dispenser.
CHP-3 STACKS.
Definition: A stack is an ordered collection of elements in which insertions(Push) and deletions(Pop) are restricted to one end. LIFO(Last In First Out)
Data Structures Evolution of algorithms for an array-based stack, queue, and linked-list. Evolved data structures used to evolve solutions to problems.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
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
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15 1.
Data Structures and Algorithms IT12112 Lecture 03.
Stacks This presentation shows – how to implement the stack – how it can be used in real applications.
Computer Science Department Data Structure and Algorithms Lecture 3 Stacks.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Stacks. What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific,
Click to edit Master text styles Stacks Data Structure.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
STACKS & QUEUES for CLASS XII ( C++).
Chapter 4 Stacks
Stacks.
Stacks and Queues Chapter 4.
Stacks and Queues.
Stack and Queue APURBO DATTA.
STACKS.
Stacks A stack is a data structure that is similar in spirit to a pile of cafeteria trays. Think about the trays in the dining halls: when the dining staff.
CMSC 341 Lecture 5 Stacks, Queues
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Stacks: Implemented using Linked Lists
Abstract Data Type Abstract Data Type as a design tool
Stacks Data structure Elements added, removed from one end only
Stacks CS-240 Dick Steflik.
Chapter 5 Stack (part 1).
Presentation transcript:

Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer

S TACK Here the elements are inserted and removed according to the last-in-first-out (LIFO) principle. Objects are inserted into a stack at any time, but only the most recently inserted object (last one!) can be removed at any time TOP BOTTOM exitEnter 1

S TACK O PERATIONS The fundamental operations involved in a stack are “push” and “pop”. push : adds a new element on the stack pop : removes an element from the stack Checking Conditions top>StackSize : Stack is full.. “Stack OVERFLOW” top== -1 : Stack is empty..”Stack UNDERFLOW” 2

O PERATIONS O N S TACK Example: Let us consider a stack with integers 14, 23, 1, 4, 45 and upper limit set to 5. Note: Every time you Push() an element inside the Stack, the TOP of the Stack gets incremented by 1 and vice- versa. When the STACK is empty, the BOTTOM and TOP of the STACK are same and pointing to the empty STACK. If you try to PUSH more elements than the upper limit of the STACK, it will cause in an overflow of data and vice-versa. Initially, the STACK is empty and the TOP of the STACK is pointing to the BOTTOM of the STACK. Stage [A]: We added 14 and TOP now points to it. Stage [B]: 23 is PUSHed and TOP is incremented by 1. Stage [C]: The STACK is FULL, as the upper limit was set to 5. Stage [D]: The TOPmost element has been POPed. The TOP gets decremented by 1. Stage [E]: 45, 4, 1 and 23 have been POPed and TOP is now pointing to the bottom most element. 3

U SING ARRAYS TO IMPLEMENT STACKS A natural way of implementing a stack is with an array Top represents the index in the array at which the next item pushed onto the stack is to be stored. This increases by one when another item is pushed onto the stack, and decreases by one when an item is popped. The stack is empty when the top =-1, and it is full if the top pointer is greater than the maximum size of the stack array. This is because top now lies beyond the bounds of the array. 4

P USHING ELEMENTS ON THE STACK Push operation adds a new element on the stack. Algorithm 1- Start 2- Let stack [size] 3- let top=-1 4- if top<stack.size then 5- top=top+1 6- stack[top]=data 7- else 8- Print ( “ Stack Is Full “, “Data Over flow”) 9- End 5

C++ I MPLEMENTATION O F P USH O PERATION static int stack[maxstk]; int top=-1; /*stack is empty*/.... main() {.... push(newvalue);.. push(newvalue);.. } push(int new) { top = top + 1; if(top < maxstk) stack[top] = new; else cout<<"Stack Overflow“ ; } 6

P OPING E LEMENTS F ROM S TACK Pop operation removes a element from the stack. Algorithm 1- Start 2- If Top>=0 then 3- print stack[top] 4- top=top-1 5- else 6- Print (“ Stack Is Empty, Data Under Flow “ ) 7- end 7

C++ I MPLEMENTATION O F P USH O PERATION static int stack[maxstk]; int top=-1;.. main(){.. poped_val = pop();.. poped_val = pop();.. } int pop(){ int del_val = 0; if(top == -1) cout<<"Stack underflow"; else { del_val = stack[top]; top = top -1; } cout<< “ Poped “ << del_val } 8

A SSIGNMENT 3 Write Java program to represent push operation for stack ( As Char ). Write Java program to represent Pop operation for stack ( As Char ). 9