10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

Infix to Prefix Conversion<br />

The input for this conversion is infix expression E and output of this is equal to<br />

expression P.This can be done by the use of stacks.<br />

ALGORITHEM FOR CONVERSION:<br />

<strong>1.</strong> Reverse the input string.<br />

2.Examine the next element in the input .<br />

3.If it is operand ,add it to the output string.<br />

4.If it closing paranthesis,push it on stacks.<br />

5.If it is an opertor ,then<br />

(a) If stackes is empty ,push‐operation on stackes.<br />

(b) If the top of stacks is closing paranthesis pus operation on stackes.<br />

(c) If it has same or higer priority then the top of stackes ,pus operator on<br />

stacks.<br />

(d) Else pop the operator from the stacks and add it to output string ,repeate<br />

S.<br />

6. If it opening paranthesis,pop operator from stackes and add them to S until a<br />

closing<br />

Paranthesis is encounter .pop and discard the closing paranthsis .<br />

7.If there is more input go to step 2.<br />

8.If there is no more input ,unstacks the remaining operators and add them.<br />

9.Reverse the output string .<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 175 ‐

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

Saved successfully!

Ooh no, something went wrong!