1 / 2

Stacks

Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as a first-in first-out data structure or a pushdown list .

fell
Télécharger la présentation

Stacks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as a first-in first-out data structure or a pushdown list. Stacks have many applications but in this case we are interested in stack register as is used in the Pentium processor. The Pentium uses an 8 word (extended 80 bit floating-point) stack register to hold numeric values. In order to evaluate an expression using a stack, we must represent it in postfix or reverse Polish notation. To convert an infix (standard mathematical notation) expression into postfix we move the operators to the right of each operand pair in order of precedence. A*(B+C/(D-E)) A*(B+C/[DE-]) A*(B+[CDE-/]) A*[BCDE-/+] ABCDE-/+* (A+B)*(C-D)/E [AB+]*[CD-]/E [AB+]*[CD-E/] AB+CD-E/* [AB+CD-*]/E AB+CD-*E/

  2. Algorithm for Converting an Infix Expression to Postfix Examine infix string from left to right 1. If next element is an operand, output it. 2. If next element is '(' push it onto a stack. 3. If next element is an operator a. If top of stack is '(' then push operator b. If top of stack is operator with higher precedence then push the operator c. Else pop operator from stack and output then repeat Step 3. 4. If next element is ')' pop and output until '(' is found, then pop and discard. 5. If more input, return to Step 1 else pop and output remaining operators.

More Related