正在加载图片...
27// determine whether Stack is full 28 bool isFul1O const Outline return top =s size -1; 31 ]// end function isFull Stack. h 33 private 4 int size; // of elements in the Stack (2of3) 35 int top; / location of the top element (-1 means empty) 36 T *stackPtr; 1/pointer to internal representation of the stack 37 ];//end class template Stack Data member stackptr is a 39// constructor template pointer to a T 40 template< typename t> 在类模板之外定义成员函数,必须以模 41 Stack< T >: Stack int s 板头( template header)开始 size(s>0?s: 10 ),// validate size top( -1 ),// stack initially empty stackPtr( new T[ size])//allocate memory for elements 45{ 46 / empty body 473//end Stack constructor template 0 2018, SEU. All rights reserved. 26© 2009, SEU. All rights reserved. © 2018, SEU. All rights reserved. 26 Outline Stack.h (2 of 3) 26 27 // determine whether Stack is full 28 bool isFull() const 29 { 30 return top == size - 1; 31 } // end function isFull 32 33 private: 34 int size; // # of elements in the Stack 35 int top; // location of the top element (-1 means empty) 36 T *stackPtr; // pointer to internal representation of the Stack 37 }; // end class template Stack 38 39 // constructor template 40 template< typename T > 41 Stack< T >::Stack( int s ) 42 : size( s > 0 ? s : 10 ), // validate size 43 top( -1 ), // Stack initially empty 44 stackPtr( new T[ size ] ) // allocate memory for elements 45 { 46 // empty body 47 } // end Stack constructor template Data member stackPtr is a pointer to a T 在类模板之外定义成员函数,必须以模 板头(template header)开始
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有