- Morgan Stanley Interview
- FinalSlips.doc
- Design Brief
- blue-book
- test1fall04
- Assignment 2
- Stack Implementation
- datastructures-110225222818-phpapp01.ppt
- 59114323-C-Meterial1
- stacks_pp
- Ibps So Professional Material
- 2.mod 2-2 stack
- Test Driven Development of MiniDC
- Blue Book
- Linked List
- Build Your Own C Interpreter
- 9781285860268_Ch02_PPT
- c_questions
- New Word 2007 Document
- Expressions
- XC8 compiler Manual
- Quiz1-OOP2Copy
- Math 7
- Lab Programs
- XC8 Compiler
- Complete Placement Ques
- Computer Concepts and C Programming July 2014
- teacher comments
- system testing
- 06-proposal-writing.ppt.pdf
- Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
- Dispatches from Pluto: Lost and Found in the Mississippi Delta
- The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution
- Yes Please
- The Unwinding: An Inner History of the New America
- Sapiens: A Brief History of Humankind
- The Emperor of All Maladies: A Biography of Cancer
- Grand Pursuit: The Story of Economic Genius
- This Changes Everything: Capitalism vs. The Climate
- A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
- The Prize: The Epic Quest for Oil, Money & Power
- Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
- John Adams
- The World Is Flat 3.0: A Brief History of the Twenty-first Century
- The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
- Smart People Should Build Things: How to Restore Our Culture of Achievement, Build a Path for Entrepreneurs, and Create New Jobs in America
- Rise of ISIS: A Threat We Can't Ignore
- The New Confessions of an Economic Hit Man
- Team of Rivals: The Political Genius of Abraham Lincoln
- Angela's Ashes: A Memoir
- Steve Jobs
- How To Win Friends and Influence People
- Bad Feminist: Essays
- You Too Can Have a Body Like Mine: A Novel
- The Incarnations: A Novel
- The Light Between Oceans: A Novel
- The Sympathizer: A Novel (Pulitzer Prize for Fiction)
- Extremely Loud and Incredibly Close: A Novel
- Leaving Berlin: A Novel
- The Silver Linings Playbook: A Novel
- The Master
- Bel Canto
- A Man Called Ove: A Novel
- Brooklyn: A Novel
- The Flamethrowers: A Novel
- The First Bad Man: A Novel
- We Are Not Ourselves: A Novel
- The Blazing World: A Novel
- The Rosie Project: A Novel
- The Love Affairs of Nathaniel P.: A Novel
- Life of Pi
- Lovers at the Chameleon Club, Paris 1932: A Novel
- The Bonfire of the Vanities: A Novel
- The Perks of Being a Wallflower
- The Cider House Rules
- A Prayer for Owen Meany: A Novel
- The Wallcreeper
- Wolf Hall: A Novel
- The Art of Racing in the Rain: A Novel
- The Kitchen House: A Novel
- Beautiful Ruins: A Novel
- Interpreter of Maladies
- Good in Bed

Stack

**Topics Covered in This Lecture
**

Applications of stack

– Reversing the string

– Balancing symbols

– Postfix expression evaluation

– Translating infix expression to postfix expression

Applications of Stack Reversing the string – push each character on to a stack as it is read. . – When the line is finished. we then pop characters off the stack. and they will come off in the reverse order.

parenthesis. 5. 3. . Read the characters until end of file. At the end of the file. then report an error. The simple algorithm for this purpose is: 1. push it onto the stack. Make an empty stack. If the popped symbol is not the corresponding opening symbol. if the stack is not empty report an error.Applications of Stack Balancing Symbols Compilers use a program that checks whether every symbol (like braces. brackets. 4. then if the stack is empty report an error. Otherwise Pop the Stack. If it is a close any thing. etc) in a program is balanced. 2. If the character is an open any thing.

b/c d*e a – a1 t2 + a2 /a1 = b/c / / t2 = a – b/c / /a2 = d*e/ . 3. 2.Polish Notation a–b/c+d*e Precedence? 1. 4.

a * b 2. +a1 c +*abc Suffix = ab* . a1c+ ab*c+ . Prefix Infix = a * b + c ((a*b) +c) Priority: 1. Suffix.Infix. a1 + c / a1 = a * b / Prefix = * a b .

/*bcd + e / f a . Suffix.+ ef/ abc*d/-ef/+ prefix =a . Prefix infix = a.*bc / d + e / f a ./*bcd + /ef -a/*bcd + /ef +-a/*bcd/ef .b * c / d + e / f suffix =a – bc* / d + e / f a – bc*d/ + e / f a – bc*d/ + ef/ abc*d/.Infix.

Infix. Prefix Infix: a+b*c–d/f+e Suffix: abc*+df/-e+ Prefix: +-+a*bc/dfe . Suffix.

Now we evaluate the following postfix expression. The resulting stack is 2 5 6 stack . it is pushed onto the stack – When an operator is seen. The first four are placed on the stack.Applications of Stack Postfix Expression Evaluation – When a number is seen. 3 6523+8*+3+* 1. then pop two elements from stack and push the result onto the stack.

so 3 and 2 are popped from the stack and their sum 5 is 5 pushed. Next a + is read. 6523+8*+3+* 3 2 5 6 stack 2.Applications of Stack evaluating the following postfix expression. 5 6 stack .

8 5 5 6 stack .Applications of Stack evaluating the following postfix expression. Next 8 is read and pushed. 6523+8*+3+* 5 5 6 stack 3.

6523+8*+3+* 8 5 5 6 stack 4.Applications of Stack evaluating the following postfix expression. Next a * is seen so 8 and 5 are popped as 8 * 5 = 40 is pushed 40 5 6 stack .

45 6 stack . Next a + is read so 40 and 5 are popped and 40 + 5 = 45 is pushed.Applications of Stack evaluating the following postfix expression. 6523+8*+3+* 40 5 6 stack 5.

6523+8*+3+* 45 6 stack 6.Applications of Stack evaluating the following postfix expression. Now 3 is pushed 3 45 6 stack .

Next symbol is + so pops 3 and 45 and pushes 45 + 3 = 48. 6523+8*+3+* 3 45 6 stack 7. 48 6 stack .Applications of Stack evaluating the following postfix expression. so push 48 in stack.

288 stack . 8. so pop the stack and we get the result. the result 6 * 48 = 288 is pushed. Finally a * is seen and 48 and 6 are popped. As there is no input.Applications of Stack evaluating the following postfix expression. 6523+8*+3+* 48 6 stack 7.

etc) then we pop entries form the stack until we find an entry of lower priority. writing symbols onto the output. writing symbols until we encounter a (corresponding) left parenthesis. then we pop the stack. ‘*’. – If we see a right parenthesis. if we read the end of input. we push the operand onto the stack. which is popped but not output. we pop the stack until it is empty. ‘(‘. it is immediately placed onto the output. – Finally. . One exception is that we never remove a ‘(‘ from the stack except when processing a ‘)’.Applications of Stack Translating infix expressions to postfix expression – When an operand is read. – If we see any other symbol (‘+’. – When an operator or left parenthesis comes then save it in the stack initially stack is empty. – When the popping is done.

Applications of Stack Translating infix expressions to postfix expression Convert the following infix expression to postfix expression. so it is passed through to the output 2. 4. a+b*c+(d*e+f)*g 1. ab output Next a * is read. a Then + is read and pushed onto the stack. First the symbol a is read. output + stack 3. so nothing is output and * is put on the . * + stack . The top entry on the operator stack has lower precedence than *. Next b is read and passed through to the output.

Checking the stack. So we pop a * and place it on the output. c is read and output. which is not of lower but equal priority. a+b*c+(d*e+f)*g abc output 5. * + stack abc*+ output + stack .Applications of Stack Converting the following infix expression to postfix expression. and then push +. Next. we find that priority of stack top symbol * is higher than + . 6. The next symbol is a +. Pop the other +.

( + stack 8. abc*+d output . The next symbol read is an ‘(‘. which. is placed on the stack. a+b*c+(d*e+f)*g 7. being of highest precedence.Applications of Stack Converting the following infix expression to postfix expression. Then d is read and output.

Next. there is no output and we push * in stack * ( + stack 10. Since open parenthesis do not get removed except when a closed parenthesis is being processed. a+b*c+(d*e+f)*g 9. abc*+de output . e is read and output. We continue by reading a *.Applications of Stack Converting the following infix expression to postfix expression.

since priority of stack top value is higher so we pop * and push +.Applications of Stack Converting the following infix expression to postfix expression. a+b*c+(d*e+f)*g 11. Now we read f and output f. abc*+de*f output . The next symbol read is a +. + ( + abc*+de* output stack 12.

* + stack 15. so the stack is emptied back to the ‘(‘. we output a +. it is pushed onto the stack. g is read and output. We read a * next. Now.Applications of Stack Converting the following infix expression to postfix expression. abc*+de*f+g output . + stack abc*+de*f+ output 14. Now we read a ‘)’. a+b*c+(d*e+f)*g 13.

a+b*c+(d*e+f)*g * + stack 16. so pop output symbols from the stack until it is empty. The input is now empty. abc*+de*f+g*+ stack output .Applications of Stack Converting the following infix expression to postfix expression.

- Morgan Stanley InterviewUploaded byOmkar Nagare
- FinalSlips.docUploaded byDipak Chavan
- Design BriefUploaded byAsanka Dikkowita
- blue-bookUploaded byanon-248433
- test1fall04Uploaded byGobara Dhan
- Assignment 2Uploaded byMarquise Rosier
- Stack ImplementationUploaded byNur Dinah Yee
- datastructures-110225222818-phpapp01.pptUploaded bySoumyaranjan Rath
- 59114323-C-Meterial1Uploaded byNagarajuRaginaboyina
- stacks_ppUploaded bybrzeczka
- Ibps So Professional MaterialUploaded byRAVI
- 2.mod 2-2 stackUploaded byrobinpt
- Test Driven Development of MiniDCUploaded byJeremiah Carter
- Blue BookUploaded byvadzim
- Linked ListUploaded byshahida18
- Build Your Own C InterpreterUploaded byRichard Ferguson
- 9781285860268_Ch02_PPTUploaded byAvishekh Anusheel Chand Sharma
- c_questionsUploaded byRanjith Ranjith
- New Word 2007 DocumentUploaded byShweta Sharma Grover
- ExpressionsUploaded byPaul Cockshott
- XC8 compiler ManualUploaded bySilvanaBrtan
- Quiz1-OOP2CopyUploaded bydiana_gui
- Math 7Uploaded bykto12
- Lab ProgramsUploaded bySuresh Vanamala
- XC8 CompilerUploaded byf
- Complete Placement QuesUploaded byanshulg08
- Computer Concepts and C Programming July 2014Uploaded byPrasad C M
- teacher commentsUploaded byapi-251904810
- system testingUploaded byerikporex839
- 06-proposal-writing.ppt.pdfUploaded byKirz Serrano