Lecture 14 - Abstract Data Types

Lecture 14 - Abstract Data Types - Abstract Data Types...

Info iconThis preview shows pages 1–16. 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

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: Abstract Data Types Stacks and Queues Abstraction ● A concept, not pertaining to a particular instance ● Control Abstraction – e.g. Standard library functions, Arithmetic operations ● Data Abstraction – Creating new data types with new functionalities/properties – Details of the implementation are usually hidden ● Benefits – Allows us to focus on bigger problems – No need to re-implement low-level systems Abstract data type (ADT) ● Custom data types that expand functionalities of simple data types ● Accessed through interfaces client – a program that uses an ADT implementation – a program that specifies the mechanisms of the ADT ● Behavior and interfaces are normally defined between users and implementors ● Users don't have to concern about specific implementation Pushdown stack ADT ● Or simply Stack ● Last-in, First-out (LIFO) discipline ● Basic operations: Push – insert a new item Pop – delete the item that was most recently inserted ● Examples: – Piling of boxes – Undo operations Stack Sample push( 'S' ) push( 'T' ) push( 'A' ) pop() push( 'C' ) push( 'K' ) S S S C T T A S T S T C S T K C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● func3() ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● func2() ● func3() ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● func3() ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● func1() ● func3() ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● func3() ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } ● main() C Call Stack int func1( void ) { return 1 ; } int func2( void ) { return 2 ; } int func3( void ) { func2(); func1(); return 3 ; } int main( void ) { func3(); return ; } Postfix Calculator ● Mathematical Expression where each operator appears after two arguments, rather than between them (infix) Infix notation (common): 5 * ( ( ( 9 + 8 ) * ( 4 * 6 ) ) + 7 ) Postfix notation: 5 9 8 + 4 6 * * 7 + * Infix to Postfix conversion ● Operand – Output ● Operator – Push into stack ● Close parenthesis – Pop operator 5 * ( ( ( 9 + 8 ) * ( 4 * 6 ) ) + 7 ) 5 Infix to Postfix conversion...
View Full Document

Page1 / 59

Lecture 14 - Abstract Data Types - Abstract Data Types...

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

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