COP3502_19_Stacks1 - Computer Science Department University...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Science Department University of Central Florida Stacks & Their Applications (Postfix/Infix) COP 3502 Computer Science I Stacks & Their Applications page 2 Outline Stacks What are they and how they work Stack Applications Infix to Postfix conversion Evaluation of Postfix expressions Stacks & Their Applications page 3 Stacks An Overview Abstract Data Type (ADT): What is an Abstract Data Type? To answer this, let us ask the negative of this: What is NOT an Abstract Data Type (in C)? int int is a built-in type in the C language double double is a built-in type in the C language There are certainly many others we can list These data types are already built into the language. Stacks & Their Applications page 4 Stacks An Overview Abstract Data Type (ADT): So again, what is an Abstract Data Type? It is a data type that is NOT built into the language It is a data type that we will build We will specify what it is, how it is used, etc. It is often defined in terms of its behavior rather than its implemented representation Nice definition from Wikipedia: An abstract data type is defined indirectly , only by the operations that may be performed on it (i.e. behavior) http://en.wikipedia.org/wiki/Abstract_data_type Stacks & Their Applications page 5 Stacks An Overview Stacks: Stacks are an Abstract Data Type They are NOT built into C We must define them and their behaviors So what is a stack? A data structure that stores information in the form of a stack. Consists of a variable number of homogeneous elements i.e. elements of the same type Stacks & Their Applications page 6 Stacks An Overview Stacks: Access Policy: The access policy for a stack is simple: the first element to be removed from the stack is the last element that was placed onto the stack The main idea is that the last item placed on to the stack is the first item removed from the stack Known as the Last in, First out access policy LIFO for short The classical example of a stack is cafeteria trays. New, clean trays are added to the top of the stack. and trays are also taken from the top So the last tray in is the first tray taken out Stacks & Their Applications page 7 Stacks An Overview Stacks: Basic Operations: PUSH: This PUSHes an item on top of the stack POP: This POPs off the top item in the stack and returns it Other important tidbit: The end of the stack, where PUSHes and POPs occur, is usually referred to as the TOP of the stack Stacks & Their Applications page 8 Stacks An Overview Top 6 Element to be inserted into S (before push) (after push) 24 13 7 22 9 Top Stack S Stack S 6 24 13 7 22 9 PUSH Operation: Stacks & Their Applications page 9 POP Operation: Stacks An Overview 6 24 13 7 22 9 Top Element removed 6 (stack after pop) 24 13 7 22 9 Top (stack before pop) 6 Stacks & Their Applications...
View Full Document

Page1 / 60

COP3502_19_Stacks1 - Computer Science Department University...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online