20_Slides-ADTs2 - AbstractDataTypescont. YinglinWang...

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

View Full Document Right Arrow Icon
CS112 Fundamentals of  Programming Abstractions Abstract Data Types—cont. Yinglin Wang CS Dept., SJTU
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of  Programming Abstractions Stack provides a storage for a  collection of data values; these  values form a sequence; The values can only be removed  or added at the end of the sequence  from a stack. Lets consider the behavior of a stack
Background image of page 2
CS112 Fundamentals of  Programming Abstractions The element Last In must be element First Out.  Abbreviated: Last In First Out  (LIFO) equally: First In, Last out a 1 Push(stack, a 1 ) stack Feature of its Behavior :
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack
Background image of page 4
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2
Background image of page 6
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2 Push(stack, a 3 ) a 3
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2 Push(stack, a 3 ) a 3 Pop(stack)
Background image of page 8
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2 Push(stack, a 3 ) a 3 Pop(stack) The element Last In must be element First Out.  Abbreviated: Last In First Out  (LIFO) equally: First In, Last out Summary to the Behavior of a stack:
Background image of page 9

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of  Programming Abstractions a 1 Push(stack, a 1 ) stack Push(stack, a 2 ) a 2 Push(stack, a 3 ) a 3 Pop(stack) If you need a storage device of such kind as stacks,  what will you do? If you want to solve a problem: Read a series of integer numbers from keyboard and then print them in  reverse order: e.g. read 12, 3, 6, 29  first,  output 29, 6, 3, 12 later. you may use stacks to solve it:
Background image of page 10
CS112 Fundamentals of  Programming Abstractions stackT   NewStack (void){        stackT stack;        stack=New(stackT);        stack->count=0;        return (stack); } /* define a stack type typedef struct { int elements[100]; int count;           }   *stackT; /* declare a variable; stackT stack; /* pop a element from a stack int pop( stackT stack ){ if(stack->count>0){                     stack-> count—;       return stack-> elements[count];
Background image of page 11

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

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

This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

Page1 / 24

20_Slides-ADTs2 - AbstractDataTypescont. YinglinWang...

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

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