正在加载图片...
1 // Fig. 14.2: Stack. h 2// stack class template 3 #ifndef STACK h Outline 4 #define STACK_H 6 template< typename t> 创建类模板 Stack,包含 Stack. h 7 class stack 类型参数乎 9 public of 3) 10 Stack( int =10 );// default constructor (stack size 10) 11 12// destructor 13 STacks 15 delete] stackPtr; deallocate internal space成员函数在参数列表中使用类型参数T 16 ]//end Stack destructor 18 bool push( const T& );/ push an element onto the stack 19 bool pop( T& ;/ pop an element off the stack 21//determine whether stack is empty 22 bool isEmptyo const 24 return top 25 ]//end function isEmpty o 2018, SEU. All rights reserved. 25© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 25 1 // Fig. 14.2: Stack.h 2 // Stack class template. 3 #ifndef STACK_H 4 #define STACK_H 5 6 template< typename T > 7 class Stack 8 { 9 public: 10 Stack( int = 10 ); // default constructor (Stack size 10) 11 12 // destructor 13 ~Stack() 14 { 15 delete [] stackPtr; // deallocate internal space for Stack 16 } // end ~Stack destructor 17 18 bool push( const T& ); // push an element onto the Stack 19 bool pop( T& ); // pop an element off the Stack 20 21 // determine whether Stack is empty 22 bool isEmpty() const 23 { 24 return top == -1; 25 } // end function isEmpty 创建类模板 Stack,包含 类型参数 T 成员函数在参数列表中使用类型参数T Outline Stack.h (1 of 3)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有