Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

Size: px
Start display at page:

Download "Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5"

Transcription

1 What is Stack? Stack 1. Stack is LIFO Structure [ Last in First Out ] 2. Stack is Ordered List of Elements of Same Type. 3. Stack is Linear List 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end called Top Visual Representation of Stack: Field Value Size of the Stack 6 Maximum Value of Stack Top 5 Minimum Value of Stack Top 0 Value of Top when Stack is Empty -1 Value of Top when Stack is Full 5 Basic Operations Performed on Stack : 1. Create 2. Push 3. Pop 4. Empty Creating Stack: 1. Stack can be created by declaring the structure with two members. 2. One Member can store the actual data in the form of array. 3. Another Member can store the position of the topmost element. typedef struct stack int data[max]; int top; stack;

2 Push on Stack: We have declared data array in the above declaration. Whenever we add any element in the data array then it will be called as Pushing Data on the Stack. Suppose top is a pointer to the top element in a stack. After every push operation, the value of top is incremented by one. Pop on Stack : Whenever we try to remove element from the stack then the operation is called as POP Operation on Stack. Some basic terms : Concept Stack Push Stack Overflow Definition The procedure of inserting a new element to the top of the stack is known as Push Operation Any attempt to insert a new element in already full stack is results into Stack Overflow.

3 Concept Stack Pop Stack Underflow Definition The procedure of removing element from the top of the stack is called Pop Operation. Any attempt to delete an element from already empty stack results into Stack Underflow. When Stack is Empty When Stack is said to empty then it does not contain any element inside it. Whenever the Stack is Empty the position of topmost element is -1. When Stack is Not Empty Whenever we add very first element then topmost position will be incremented by 1. After adding First Element top = 0. After Deletion of 1 Element Top Will be Decremented by 1 Position of Top and Its Value: Position of Top Status of Stack -1 Stack is Empty 0 First Element is Just Added into Stack N-1 Stack is said to Full N Stack is said to be Overflow Values of Stack and Top: Operation Explanation top = -1-1 indicated Empty Stack top = top + 1 After push operation value of top is incremented by integer 1 top = top 1 After pop operation value of top is decremented by 1 Check Whether Stack is Empty or Not? We are using Empty Function for Checking whether stack is empty or not 1. Function returns True if Stack is Empty. 2. Function returns False if Stack is Non-Empty. 3. Function Takes Pointer to Stack int empty (stack *s)

4 1. Return Type : Integer. [Empty Stack Return 1, Non Empty Stack Return 0 ] 2. Parameter : Address of Variable of Type Stack. 3. How to Call this Function From Main? typedef struct stack int data[max]; int top; stack; Empty Function : int empty(stack *s) if(s->top == -1) //Stack is Empty return(1); else return(0); stack; Check Whether Stack is Full or Not? We are using Empty Function for Checking whether stack is full or not 1. Function returns True if Stack is Full 2. Function returns False if Stack is Not Full. 3. Function Takes Pointer to Stack int full (stack *s) 1. Return Type : Integer. [If full Stack Return 1, not full Stack Return 0 ] 2. Parameter : Address of Variable of Type Stack. How to Call this Function From Main? typedef struct stack int data[max]; int top; stack; void main() stack s; // Declare Stack Variable i = full(&s); // Pass By Reference Pass Stack Variable to full Function using pass by reference. 2. As full Function returns integer, we have facility to store returned value into some integer variable so we have written [ i = full(&s) ]

5 Complete Code int full(stack *s) if(s->top == MAX-1) //Stack is Full return(1); else return(0); Push Operation: 1. Push Refers as Adding Elements onto Stack. 2. Push Operation carried out in following 2 steps o o First Increment Variable top so that it now refers to next memory location. Secondly Add Element Onto Stack by accessing array. 3. Main Function Should ensure that stack is not full before making call to push() in order to prevent Stack Overflow Push Function void push(stack *s,int num) s->top = s->top + 1; s->data[s->top] = num; Pop Operation Arguments and Return Type : 1. Argument : Variable of Type Stack. 2. Return Type : Integer [ Removed Element ] Steps in Pop Operation : 1. Store Topmost Element in another Variable. 2. Decrement Top by 1 3. Return Topmost Element. Pre-requisites : Stack Type Definition.: Click Here Pop Function : int pop(stack *s) int x; x = s->data[s->top]; s->top = s->top - 1; return(x);

6 Application of Stack : 1. Parsing 2. Recursive Function 3. Calling Function 4. Expression Evaluation 5. Expression Conversion I. Infix to Postfix II. III. IV. Infix to Prefix Postfix to Infix Prefix to Infix 6. Towers of hanoi Expression Representation Techniques : 1. Infix Expression 2. Prefix Expression 3. Postfix Expression Evaluation of Postfix Expression : [ Click Here ] Expression Example Note Infix a + b Operator Between Operands Prefix + a b Operator before Operands Postfix a b + Operator after Operands Generally postfix expressions are free from Operator Precedence thats why they are preferred in Computer system.computer System Uses Postfix form to represent expression. Following is the example that shows evaluation of the Postfix expression using stack as data structure. Algorithm for Evaluation of Postfix Expression Initialize(Stack S) x = ReadToken(); // Read Token while(x) if ( x is Operand ) Push ( x ) Onto Stack S. if ( x is Operator )

7 Operand2 = Pop(Stack S); Operand2 = Pop(Stack S); Evaluate (Operand1,Operand2,Operator x); x = ReadNextToken(); // Read Token

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation

More information

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks Stack Chapter 4 Outline Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications Recursive Programming Evaluation of Expressions ADT for stacks Introduction

More information

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Stack Operations on a stack Representing stacks Converting an expression

More information

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS AND QUEUES. Problem Solving with Computers-II STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()

More information

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi Data Structures & Algorithm Analysis Lec(3) Stacks Lecturer: Souad Alonazi What is a stack? Stores a set of elements in a particular order Stack principle: LAST IN FIRST OUT = LIFO It means: the last element

More information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows: STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The

More information

Data Structures Week #3. Stacks

Data Structures Week #3. Stacks Data Structures Week #3 Stacks Outline Stacks Operations on Stacks Array Implementation of Stacks Linked List Implementation of Stacks Stack Applications October 5, 2015 Borahan Tümer, Ph.D. 2 Stacks (Yığınlar)

More information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

Associate Professor Dr. Raed Ibraheem Hamed

Associate Professor Dr. Raed Ibraheem Hamed Associate Professor Dr. Raed Ibraheem Hamed University of Human Development, College of Science and Technology Computer Science Department 2015 2016 1 What this Lecture is about: Stack Structure Stack

More information

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms... First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms.... Q1) What are some of the applications for the tree data structure? Q2) There are 8, 15, 13, and

More information

Infix to Postfix Conversion

Infix to Postfix Conversion Infix to Postfix Conversion Infix to Postfix Conversion Stacks are widely used in the design and implementation of compilers. For example, they are used to convert arithmetic expressions from infix notation

More information

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack. STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is

More information

Stacks. Manolis Koubarakis. Data Structures and Programming Techniques

Stacks. Manolis Koubarakis. Data Structures and Programming Techniques Stacks Manolis Koubarakis 1 Stacks and Queues Linear data structures are collections of components arranged in a straight line. If we restrict the growth of a linear data structure so that new components

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

Stacks and Queues. CSE Data Structures April 12, 2002

Stacks and Queues. CSE Data Structures April 12, 2002 Stacks and Queues CSE 373 - Data Structures April 12, 2002 Readings and References Reading Section 3.3 and 3.4, Data Structures and Algorithm Analysis in C, Weiss Other References 12-Apr-02 CSE 373 - Data

More information

DS Assignment II. Full Sized Image

DS Assignment II. Full Sized Image DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed stack method of expression evaluation in 1955. Topic 15 Implementing and Using "stack n. The set of things a person has to do in the future. "I haven't done it yet because every time I pop my stack something new gets pushed." If you are interrupted

More information

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms Introduction Problem Solving on Computer Data Structures (collection of data and relationships) Algorithms 1 Objective of Data Structures Two Goals: 1) Identify and develop useful high-level data types

More information

Sample Question Paper

Sample Question Paper Scheme - I Sample Question Paper Marks : 70 Time: 3 Hrs. Q.1) Attempt any FIVE of the following. 10 Marks a. Write any four applications of data structure. b. Sketch the diagram of circular queue. c. State

More information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS THE STACK

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS THE STACK Contents: Definition and Examples Representing stacks in C Example: infix, prefix, and postfix Exercises THE STACK Definition and Examples A stack is an ordered collection of items into which new items

More information

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017 Stack Applications Lecture 27 Sections 18.7-18.8 Robb T. Koether Hampden-Sydney College Wed, Mar 29, 2017 Robb T. Koether Hampden-Sydney College) Stack Applications Wed, Mar 29, 2017 1 / 27 1 Function

More information

Stacks Calculator Application. Alexandra Stefan

Stacks Calculator Application. Alexandra Stefan Stacks Calculator Application Alexandra Stefan Last modified 2/6/2018 1 Infix and Postfix Notation The standard notation we use for writing mathematical expressions is called infix notation. The operators

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

March 13/2003 Jayakanth Srinivasan,

March 13/2003 Jayakanth Srinivasan, Statement Effort MergeSort(A, lower_bound, upper_bound) begin T(n) if (lower_bound < upper_bound) Θ(1) mid = (lower_bound + upper_bound)/ 2 Θ(1) MergeSort(A, lower_bound, mid) T(n/2) MergeSort(A, mid+1,

More information

Computer Science BS Degree - Data Structures (I2206) Abstract Data Types (ADT)

Computer Science BS Degree - Data Structures (I2206) Abstract Data Types (ADT) Abstract Data Types (ADT) 70 Hierarchy of types Each type is implemented in terms if the types lower in the hierarchy Level 0 Bit Byte Word Level 1 Integer Real Char Boolean Pointer Level 2 Array Record

More information

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU Data Structures Chapter 06 1 Stacks A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. This means that elements are removed from

More information

Chapter 9 STACK, QUEUE

Chapter 9 STACK, QUEUE Chapter 9 STACK, QUEUE 1 LIFO: Last In, First Out. Stacks Restricted form of list: Insert and remove only at front of list. Notation: Insert: PUSH Remove: POP The accessible element is called TOP. Stack

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which

More information

STACKS 3.1 INTRODUCTION 3.2 DEFINITION

STACKS 3.1 INTRODUCTION 3.2 DEFINITION STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called

More information

CS 211. Project 5 Infix Expression Evaluation

CS 211. Project 5 Infix Expression Evaluation CS 211 Project 5 Infix Expression Evaluation Part 1 Create you own Stack Class Need two stacks one stack of integers for the operands one stack of characters for the operators Do we need 2 Stack Classes?

More information

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table Contents #06 More Structures -07 FUNDAMENTAL PROGRAMMING I Stack Queue Hash table DEPARTMENT OF COMPUTER ENGINEERING, PSU v. Queue vs. Stack Stack Operations IN IN OUT Push: add an item to the top Pop:

More information

Stacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms

Stacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Stacks and Queues Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Two New ADTs Define two new abstract data types Both are restricted lists Can be implemented using arrays

More information

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero). Suppose we have a circular array implementation of the queue,with ten items in the queue stored at data[2] through data[11]. The current capacity of an array is 12. Where does the insert method place the

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

n Data structures that reflect a temporal relationship q order of removal based on order of insertion n We will consider:

n Data structures that reflect a temporal relationship q order of removal based on order of insertion n We will consider: Linear, time-ordered structures CS00: Stacks n Prichard Ch 7 n Data structures that reflect a temporal relationship order of removal based on order of insertion n We will consider: first come,first serve

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 5: Stacks and Queues 2017 Fall Stacks A list on which insertion and deletion can be performed. Based on Last-in-First-out (LIFO) Stacks are used for a number of applications:

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

Stacks Stack Examples:

Stacks Stack Examples: Stacks 1 Stacks A Stack is a sequential organization of items in which the last element inserted is the first element removed. They are often referred to as LIFO, which stands for last in first out. Examples:

More information

An Introduction to Trees

An Introduction to Trees An Introduction to Trees Alice E. Fischer Spring 2017 Alice E. Fischer An Introduction to Trees... 1/34 Spring 2017 1 / 34 Outline 1 Trees the Abstraction Definitions 2 Expression Trees 3 Binary Search

More information

Stacks and their Applications

Stacks and their Applications Stacks and their Applications Lecture 23 Sections 18.1-18.2 Robb T. Koether Hampden-Sydney College Fri, Mar 16, 2018 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018

More information

Stacks. Revised based on textbook author s notes.

Stacks. Revised based on textbook author s notes. Stacks Revised based on textbook author s notes. Stacks A restricted access container that stores a linear collection. Very common for solving problems in computer science. Provides a last-in first-out

More information

Stacks, Queues and Hierarchical Collections

Stacks, Queues and Hierarchical Collections Programming III Stacks, Queues and Hierarchical Collections 2501ICT Nathan Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2 Copyright 2002- by

More information

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard IV. Stacks 1 A. Introduction 1. Consider the problems on pp. 170-1 (1) Model the discard pile in a card game (2) Model a railroad switching yard (3) Parentheses checker () Calculate and display base-two

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS Data Structure Using C -8- NCS DATA STRUCTURE USING C Unit- Part- Stack Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncsds.wordpress.com Introduction Stack is a non

More information

Monday, November 13, 2017

Monday, November 13, 2017 Monday, November 13, 2017 Topics for today ode generation nalysis lgorithm 1: evaluation of postfix lgorithm 2: infix to postfix lgorithm 3: evaluation of infix lgorithm 4: infix to tree nalysis We are

More information

Prepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1

Prepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1 Basics : Abstract Data Type(ADT) introduction to data structures representation - implementation Stack and list: representing stack implementation application balancing symbols conversion of infix to postfix

More information

Programming, Data Structures and Algorithms Prof. Hema A Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming, Data Structures and Algorithms Prof. Hema A Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras Programming, Data Structures and Algorithms Prof. Hema A Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 54 Assignment on Data Structures (Refer Slide

More information

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues The Bucharest University of Economic Studies Data Structures ADTs-Abstract Data Types Stacks and Queues Agenda Definition Graphical representation Internal interpretation Characteristics Operations Implementations

More information

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1 QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Alice E. Fischer Lecture 6: Stacks 2018 Alice E. Fischer Data Structures L5, Stacks... 1/29 Lecture 6: Stacks 2018 1 / 29 Outline 1 Stacks C++ Template Class Functions 2

More information

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web:     Ph: Serial : 1PT_CS_A+C_Programming & Data Structure_230918 Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: E-mail: info@madeeasy.in Ph: 011-45124612 CLASS TEST 2018-19

More information

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Stacks, Queues and Hierarchical Collections. 2501ICT Logan Stacks, Queues and Hierarchical Collections 2501ICT Logan Contents Linked Data Structures Revisited Stacks Queues Trees Binary Trees Generic Trees Implementations 2 Queues and Stacks Queues and Stacks

More information

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples:

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples: Ch. 8: ADTs: Stacks and Queues Abstract Data Type A data type for which: CS 8 Fall Jill Seaman - only the properties of the data and the operations to be performed on the data are specific, - not concerned

More information

CS 211 Programming Practicum Spring 2018

CS 211 Programming Practicum Spring 2018 Due: Thursday, 4/5/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced Delimiters in an Infix Algebraic Expression A Problem Solved:

More information

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified. The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO - last in, first out Stacks 2 The

More information

(3-2) Basics of a Stack. Instructor - Andrew S. O Fallon CptS 122 (January 26, 2018) Washington State University

(3-2) Basics of a Stack. Instructor - Andrew S. O Fallon CptS 122 (January 26, 2018) Washington State University (3-2) Basics of a Stack Instructor - Andrew S. O Fallon CptS 122 (January 26, 2018) Washington State University What is a Stack? A finite sequence of nodes, where only the top node may be accessed Insertions

More information

Computer Science. Section 1B

Computer Science. Section 1B Computer Science Foundation Exam August 8, 2008 Computer Science Section 1B KEY Name: SSN: Max Pts Passing Pts Category Q1 10 6 KNW Q2 8 4 CMP Q3 12 8 ANL Q4 8 6 DSN Q5 12 8 DSN Total 50 32 Score You have

More information

1. Stack Implementation Using 1D Array

1. Stack Implementation Using 1D Array Lecture 5 Stacks 1 Lecture Content 1. Stack Implementation Using 1D Array 2. Stack Implementation Using Singly Linked List 3. Applications of Stack 3.1 Infix and Postfix Arithmetic Expressions 3.2 Evaluate

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 6: Stacks and Queues 2015-2016 Fall Stacks A list on which insertion and deletion can be performed. Based on Last-in-First-out (LIFO) Stacks are used for a number of applications:

More information

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \ BSc IT C Programming (2013-2017) Unit I Q1. What do you understand by type conversion? (2013) Q2. Why we need different data types? (2013) Q3 What is the output of the following (2013) main() Printf( %d,

More information

ADTs Stack and Queue. Outline

ADTs Stack and Queue. Outline Chapter 5 ADTs Stack and Queue Fall 2017 Yanjun Li CS2200 1 Outline Stack Array-based Implementation Linked Implementation Queue Array-based Implementation Linked Implementation Comparison Fall 2017 Yanjun

More information

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

More information

CS 211 Programming Practicum Spring 2017

CS 211 Programming Practicum Spring 2017 Due: Tuesday, 3/28/17 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a JAVA program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Stack and Its Implementation

Stack and Its Implementation Stack and Its Implementation Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131 1 Definition of Stack Usage of Stack Outline

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

The program simply pushes all of the characters of the string into the stack. Then it pops and display until the stack is empty.

The program simply pushes all of the characters of the string into the stack. Then it pops and display until the stack is empty. EENG212 Algorithms & Data Structures Fall 0/07 Lecture Notes # Outline Stacks Application of Stacks Reversing a String Palindrome Example Infix, Postfix and Prefix Notations APPLICATION OF STACKS Stacks

More information

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.

More information

Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

More information

Data Structure. Recitation IV

Data Structure. Recitation IV Data Structure Recitation IV Topic Java Generics Java error handling Stack Lab 2 Java Generics The following code snippet without generics requires casting: List list = new ArrayList(); list.add("hello");

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION DATA STRUCTURES AND ALGORITHMS 09 STACK APPLICATION REVERSE POLISH NOTATION IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES

More information

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Copyright 2012 by Pearson Education, Inc. All rights reserved Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

List, Stack, and Queues

List, Stack, and Queues List, Stack, and Queues R. J. Renka Department of Computer Science & Engineering University of North Texas 02/24/2010 3.1 Abstract Data Type An Abstract Data Type (ADT) is a set of objects with a set of

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Postfix (and prefix) notation

Postfix (and prefix) notation Postfix (and prefix) notation Also called reverse Polish reversed form of notation devised by mathematician named Jan Łukasiewicz (so really lü-kä-sha-vech notation) Infix notation is: operand operator

More information

Answer D) ADT does not depend on the implementation

Answer D) ADT does not depend on the implementation Week 5 Solutions 1.Which of the following is not correct with respect to an Abstract Data Type (ADT)? A) There can be several implementations of the same ADT. B) ADT encapsulates the representation of

More information

Stacks (Section 2) By: Pramod Parajuli, Department of Computer Science, St. Xavier s College, Nepal.

Stacks (Section 2) By: Pramod Parajuli, Department of Computer Science, St. Xavier s College, Nepal. (Section 2) Linked list implementation of stack Typical Application of stacks Evaluation of expressions (infix, postfix, prefix) References and further details By: Pramod Parajuli, Department of Computer

More information

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract Data Types Stack January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract data types and data structures An Abstract Data Type (ADT) is: A collection of data Describes what data are stored but

More information

1 P age DS & OOPS / UNIT II

1 P age DS & OOPS / UNIT II UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Containers: Stack. Jordi Cortadella and Jordi Petit Department of Computer Science

Containers: Stack. Jordi Cortadella and Jordi Petit Department of Computer Science Containers: Stack Jordi Cortadella and Jordi Petit Department of Computer Science The Stack ADT A stack is a list of objects in which insertions and deletions can only be performed at the top of the list.

More information

Types of Data Structures

Types of Data Structures DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data

More information

Formal Languages and Automata Theory, SS Project (due Week 14)

Formal Languages and Automata Theory, SS Project (due Week 14) Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string

More information

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015 Stack Applications Lecture 25 Sections 18.7-18.8 Robb T. Koether Hampden-Sydney College Mon, Mar 30, 2015 Robb T. Koether Hampden-Sydney College) Stack Applications Mon, Mar 30, 2015 1 / 34 1 The Triangle

More information

The Stack and Queue Types

The Stack and Queue Types The Stack and Queue Types Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html 2 Programming Principle of the Day Do the simplest thing that could possibly work A good

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

SCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING. EKT224: ALGORITHM AND DATA STRUCTURES (Stack, Queue, Linked list)

SCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING. EKT224: ALGORITHM AND DATA STRUCTURES (Stack, Queue, Linked list) ASSIGNMENT 2 SCHOOL OF COMPUTER AND COMMUNICATION ENGINEERING EKT224: ALGORITHM AND DATA STRUCTURES (Stack, Queue, Linked list) Date: 30/9/2015 Due Date: 30/10/2015 Early Bird Date: 23/10/2015 QUESTION

More information

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

Lecture 4 Stack and Queue

Lecture 4 Stack and Queue Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can

More information