《C语言堆栈算法数.ppt》由会员分享,可在线阅读,更多相关《C语言堆栈算法数.ppt(6页珍藏版)》请在金锄头文库上搜索。
1、C语言堆栈算法数制转换,22栋附102寝室 谌敦斌、郭燚、耿凯、董楗、 梁攀攀、鄢应钊,2,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; ,3,Stack.c,int push(stack* s, int val) if(s-sp -
2、 s-base = s-size) puts(overflow); exit(1); return *s-sp+ = val; int pop(stack* s) if(s-sp = s-base) puts(underflow); exit(2); return *-s-sp; ,4,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, ,5,Stack.c,int conversion (int n,int r) stack s; init( ,6,运行,15 2 1 1 1 1 Press any key to continue 98 8 1 4 2 Press any key to continue 100 16 6 4 Press any key to continue,