设计一算法,删除栈S中所有与变量C相同的元素。

分类: 数据结构(02331) 发布时间: 2024-08-04 00:42 浏览量: 2
设计一算法,删除栈S中所有与变量C相同的元素。
【正确答案】:void ex(seqStack*s,int c) { SeqStack T; int d; while(!StackEmpty(S)) { d=pop(S); if(d!=c)push(T,d); } while(!StackEmpty(T)) { d=pop(T); push(S,d); } }