C语言堆栈算法数

上传人:博****1 文档编号:580463521 上传时间:2024-08-29 格式:PPT 页数:6 大小:104.51KB
返回 下载 相关 举报
C语言堆栈算法数_第1页
第1页 / 共6页
C语言堆栈算法数_第2页
第2页 / 共6页
C语言堆栈算法数_第3页
第3页 / 共6页
C语言堆栈算法数_第4页
第4页 / 共6页
C语言堆栈算法数_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《C语言堆栈算法数》由会员分享,可在线阅读,更多相关《C语言堆栈算法数(6页珍藏版)》请在金锄头文库上搜索。

1、C语言堆栈算法数制转换22栋附102寝室谌敦斌、郭燚、耿凯、董楗、梁攀攀、鄢应钊1 1Stack.c#include #include #include #include int conversion(int n,int r);int conversion(int n,int r);typedef struct _stack typedef struct _stack int size; int size; int* base; int* base; int* sp; int* sp; stack; stack;void init(stack* s, int n)void init(stack

2、* s, int n) s-base = (int*)malloc(sizeof(int)*n); s-base = (int*)malloc(sizeof(int)*n); s-size = n; s-size = n; s-sp = s-base; s-sp = s-base; 2 2Stack.cint push(stack* s, int val)int push(stack* s, int val) if(s-sp - s-base = s-size) if(s-sp - s-base = s-size) puts(overflow); puts(overflow); exit(1)

3、; exit(1); return *s-sp+ = val; return *s-sp+ = val; int pop(stack* s)int pop(stack* s) if(s-sp = s-base) if(s-sp = s-base) puts(underflow); puts(underflow); exit(2); exit(2); return *-s-sp; return *-s-sp; 3 3Stack.cint empty(stack* s)int empty(stack* s) return s-sp = s-base; return s-sp = s-base; v

4、oid clean(stack* s)void clean(stack* s) if(s-base) if(s-base) free(s-base); free(s-base); int main()int main() int n,r; int n,r; scanf(%d%d,&n,&r); scanf(%d%d,&n,&r);if(r=2)if(r=2)conversion(n,r);conversion(n,r); return 0; return 0; 4 4Stack.cint conversion (int n,int r)int conversion (int n,int r)

5、stack s; stack s; init(&s, 100); init(&s, 100); while(n) while(n) push(&s,n%r); push(&s,n%r); n=n/r; n=n/r; while(!empty(&s) while(!empty(&s) printf(%d , pop(&s); printf(%d , pop(&s); clean(&s); clean(&s); return 0; return 0; 5 5运行15 21 1 1 1 Press any key to continue98 81 4 2 Press any key to continue100 166 4 Press any key to continue6 6

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号