/
Stack Application Stack Application

Stack Application - PowerPoint Presentation

celsa-spraggs
celsa-spraggs . @celsa-spraggs
Follow
441 views
Uploaded On 2016-09-12

Stack Application - PPT Presentation

1 Bracket Matching CG1103 Data Structures and Algorithms I Ensures that pairs of brackets are properly matched eg for mathematical expressions programs A good example a ID: 465111

brackets stack error bracket stack brackets bracket error closing ex3 empty lab1 opening flag algorithms structures data cg1103 matching

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Stack Application" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Stack Application 1: Bracket Matching

[ CG1103 Data Structures and Algorithms I ]

Ensures that pairs of brackets are properly matched.e.g., for mathematical expressions, programs

A good example: {a,(b+f[4])*3,d+f[5]}

Incorrect examples: (..)..) // too many closing brackets (..(..) // too many opening brackets [..(..]..) // mismatched brackets

Lab1 Ex3Slide2

Stack Application 1: Bracket Matching

[ CG1103 Data Structures and Algorithms I ]

create empty

stack

for every char read{ if is open bracket then

push

onto stack if is close bracket, then

pop from the stack

if doesn’t match or underflow then

flag error }

if

stack is not empty then flag errorExample

{ a,( b + f [ 4 ] ) * 3, d + f [ 5 ]

}

Stack

{

(

[

)

}

]

[

]

Q

: What type of error does

the last line test for?

A: too many closing brackets

B: too many opening brackets

C: bracket mismatch

Lab1 Ex3