top→b to p top→空栈 →a进栈 b进栈 to p to p- edcb Eeacb 进栈示例 进栈 Z进栈溢出
进栈示例
to p edcba top-d top- b dcbg 退栈 e退栈 d退栈 b 退栈示例 top→a退栈tp→空栈
退栈示例
template <class Type> void Stack<Type>:: Push( const Type item)& assert(!sFull (); /先决亲件断言 elements[++top]=iem;∥加入新元素 template <class Type> Type Stack<Type>:: Popoi aert(! IsEmpty());∥先决条件断言 return elements[op-;∥出栈顶元素
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--]; //退出栈顶元素 }
template <class Type> Type stack<Type>:: GetTop oi assert(! EMpty());∥先决条件断言 return elements[tp]l;∥取出栈顶元素 双栈共享一个栈空间 maxSize-1 V 6[0 t[0 t[1] b1
template <class Type> Type stack<Type>:: GetTop ( ) { assert ( !IsEmpty ( ) ); //先决条件断言 return elements[top]; //取出栈顶元素 }
多栈处理栈浮动技术 n栈共享一个数组空间vml a设立栈顶指针数组t+1和 栈底指针数组bn+1l 和b分别指示第个栈的栈顶与栈底 bm作为控制量,指到数组最高下标 各栈初始分配空间s=Lm/n」 指针初始值40]=b0=-1bl=m-1 t[i=b=b[-1]+s,i=1,2,…,n-1