正在加载图片...
顺序栈基本操作的实现(算法4.4、4.5) const int SQSTACK INC SIZE = 10; void Increment (SqStack &S, int inc size= SQSTACK_INC_SIZE)[ ElemType *a= new ElemType[s stacksize inc size]; for (int i=0; i<=S top; ++i)alil=selem[i] delete Selem;selem=a; s. stacksize + inc size; void Push sq (SqStack &S, ElemType e)i if (s top== S. stacksize-1)Increment(S); elem[++s top]=ej bool Pop sq(sqstack &S, ElemType &e)t if (stop ==-1)return false; e=selems.top--] return true 2021/1/29 数据结构及其算法第4章栈和队列•顺序栈基本操作的实现(算法4.4、4.5) 2021/1/29 数据结构及其算法 第4章 栈和队列 7 const int SQSTACK_INC_SIZE = 10; void Increment(SqStack &S, int inc_size = SQSTACK_INC_SIZE) { ElemType *a = new ElemType[S.stacksize + inc_size]; for (int i=0; i<=S.top; ++i) a[i] = S.elem[i]; delete []S.elem; S.elem = a; S.stacksize += inc_size; } void Push_sq(SqStack &S, ElemType e) { if (S.top == S.stacksize-1) Increment(S); S.elem[++S.top] = e; } bool Pop_sq(SqStack &S, ElemType &e) { if (S.top == -1) return false; e = S.elem[S.top--]; return true; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有