《C语言堆栈算法数.ppt》由会员分享,可在线阅读,更多相关《C语言堆栈算法数.ppt(6页珍藏版)》请在三一办公上搜索。
1、C语言堆栈算法数制转换,22栋附102寝室谌敦斌、郭燚、耿凯、董楗、梁攀攀、鄢应钊,Stack.c,#include#include int conversion(int n,int r);typedef struct _stack int size;int*base;int*sp;stack;void init(stack*s,int n)s-base=(int*)malloc(sizeof(int)*n);s-size=n;s-sp=s-base;,Stack.c,int push(stack*s,int val)if(s-sp-s-base=s-size)puts(overflow);e
2、xit(1);return*s-sp+=val;int pop(stack*s)if(s-sp=s-base)puts(underflow);exit(2);return*-s-sp;,Stack.c,int empty(stack*s)return s-sp=s-base;void clean(stack*s)if(s-base)free(s-base);int main()int n,r;scanf(%d%d,Stack.c,int conversion(int n,int r)stack s;init(,运行,15 21 1 1 1 Press any key to continue98 81 4 2 Press any key to continue100 166 4 Press any key to continue,