23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.1.5 Match<strong>in</strong>g Parentheses <strong>and</strong> HTML Tags<br />

In this subsection, we explore two related applications of stacks, the first of which<br />

is for match<strong>in</strong>g parentheses <strong>and</strong> group<strong>in</strong>g symbols <strong>in</strong> arithmetic expressions.<br />

Arithmetic expressions can conta<strong>in</strong> various pairs of group<strong>in</strong>g symbols, such as<br />

• Parentheses: "(" <strong>and</strong> ")"<br />

• Braces: "{" <strong>and</strong> "}"<br />

• Brackets: "[" <strong>and</strong> "]"<br />

• Floor function symbols: " " <strong>and</strong> ""<br />

• Ceil<strong>in</strong>g function symbols: "" <strong>and</strong> ","<br />

<strong>and</strong> each open<strong>in</strong>g symbol must match with its correspond<strong>in</strong>g clos<strong>in</strong>g symbol. For<br />

example, a left bracket, "[," must match with a correspond<strong>in</strong>g right bracket, "]," as<br />

<strong>in</strong> the follow<strong>in</strong>g expression:<br />

[(5 + x) − (y + z)].<br />

279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!