{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 1_stack - Stacks and Queues Abstract Stacks Data Types...

This preview shows pages 1–18. Sign up to view the full content.

Stacks and Queues

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

View Full Document
! Abstract Data Types ! Stacks ! Queues ! Priority Queues September 2004 John Edgar 2
September 2004 John Edgar 3

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

View Full Document
! Reverse Polish Notation (RPN) ! Also known as postfix notation ! A mathematical notation Where every operator follows its operands ! Invented by Jan Ł ukasiewicz in 1920 ! Example ! Infix: 5 + ((1 + 2) * 4) 3 ! RPN: 5 1 2 + 4 * + 3 – September 2004 John Edgar 4
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 5 5 store 5 store 1 store 2 Apply + to the last two operands 1 2

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

View Full Document
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 6 5 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands 3 4
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 7 5 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result 12 Apply + to the last two operands

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

View Full Document
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 8 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result store 3 Apply + to the last two operands store result 3 Apply - to the last two operands 17
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 9 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result store 3 Apply + to the last two operands store result Apply - to the last two operands 14 store result retrieve answer

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

View Full Document
! What are the storage properties of the data structure that we used? ! Specifically how are items inserted and removed? ! The last item to be entered is the first item to be removed ! Known as LIFO (Last In First Out) ! A stack September 2004 John Edgar 10
September 2004 John Edgar 11

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

View Full Document
! A stack only allows items to be inserted and removed at one end ! We call this end the top of the stack ! The other end is called the bottom ! Access to other items in the stack is not allowed September 2004 John Edgar 12
! A stack can be used to naturally store data for postfix notation ! Operands are stored at the top of the stack ! And removed from the top of the stack ! Notice that we have not (yet) discussed how a stack should be implemented ! Just what it does ! An example of an Abstract Data Type September 2004 John Edgar 13

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

View Full Document
September 2004 John Edgar 14
! A collection of data ! Describes the data but not how it is stored ! Set of operations on the data ! Describes precisely what effect the operations have on the data but ! Does not specify how operations are carried out ! An ADT is not a data structure September 2004 John Edgar 15

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

View Full Document
! The term concrete data type is usually used in contrast with an ADT ! An ADT is a collection of data and a set of operations on the data ! A concrete data type is an implementation of an ADT using a data structure ! A construct that is defined in a programming language to store a collection of data September 2004 John Edgar 16
!

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 114

1_stack - Stacks and Queues Abstract Stacks Data Types...

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

View Full Document
Ask a homework question - tutors are online