ds04 - C lo u d s ■ ( & ( Stack ) Stack ) ■ ( (...

Info iconThis preview shows pages 1–13. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C lo u d s ■ ( & ( Stack ) Stack ) ■ ( ( Queue ) Queue ) ■- ( ( Priority Queue) Priority Queue) & ( Stack ) ( Stack ) ■- 0 3 ♥ 0= 3 ■- ♥ Xßë ♥ ( ( top top ) ) ♥ ( ( bottom bottom ) ) ■ t X ( ( LIFO LIFO ) ) template <class Type> class Stack { public: Stack ( int = 10 ) ; // t void Push ( const Type & item ) ; // t Type Pop ( ) ; // t Type GetTop ( ) ; // void MakeEmpty ( ) ; // t int IsEmpty ( ) const; // t int IsFull ( ) const; // t } ª #include <assert.h> template <class Type> class Stack { public: Stack ( int = 10 ) ; // t ~Stack ( ) { delete [ ] elements ; } // t void Push ( const Type & item ) ; // t Type Pop ( ) ; // t Type GetTop ( ) ; // void MakeEmpty ( ) { top=- 1 ; } // t int IsEmpty ( ) const { return top ==- 1 ; } ª — 3 — ( int IsFull ( ) const { return top == maxSize- 1 ; } private: int top ; // 1 Type *elements ; // t int maxSize ; // 1 } template <class Type> Stack <Type>:: Stack ( int s ) : top (- 1) , maxSize ( s ) { elements = new Type [ maxSize ] ; assert ( elements != 0 ) ; // t } template <class Type> void Stack <Type>:: Push ( const Type & item ) { assert ( ! IsFull ( ) ) ; // elements [ ++top ] = item ; // } template <class Type> Type Stack <Type>:: Pop ( ) { assert ( ! IsEmpty ( ) ) ; // return elements [ top-- ] ; // g } template <class Type> Type stack <Type>:: GetTop ( ) { assert ( ! IsEmpty ( ) ) ; // return elements [ top ] ; // } ª à à & €À ■ n n ª à ✸ V V [ [ m m ] ] ■ ª t t [ [ n n +1] +1] t ˆp<¾ª* b b [ [ n n +1] +1] ■ t t [ [ i i ] ] t b b [ [ i i ] ]- ¾ t t i i o o o o o b b [ [ n n ] ] ¾ª* à 3 ¾ ♥ * Ð)3E ■ ¾ª* s s = = m m / / n n ■ - ¾ª ¾ ♥ t t [0] = [0] = b b [0] = -1 [0] = -1 b b [ [ n n ] = ] = m m-1 -1 t t [ [ i i ] = ] = b b [ [ i i ] = ] = b b [ [ i i-1] + -1] + s s , , i i = 1, 2, …, = 1, 2, …, n n-1 -1 8 zC StackFull ( ) template < class Type > void Push ( const int i , const Type & item ) { if ( t [ i ] == b [ i +1] ) StackFull ( i ) ; else V [++ t [ i ]] = item ; // t i t } template <class Type> Type...
View Full Document

This note was uploaded on 09/30/2011 for the course CS 255 taught by Professor Gangli during the Spring '11 term at Tsinghua University.

Page1 / 43

ds04 - C lo u d s ■ ( & ( Stack ) Stack ) ■ ( (...

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

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