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

作者:高老师 浏览 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); } }

📱 扫码体验刷题小程序

微信小程序二维码

扫一扫使用我们的微信小程序

热门题目

已复制到剪贴板