菜鸟用链栈写的进制转换
2012-02-22 23:35
218 查看
#include<stdio.h> #include<stdlib.h> struct Lnode/*以为当时做的题目没有告诉我是多少位的数字所以我选择了长度不受限的链栈*/ { int num; struct Lnode *next; }; int Push(struct Lnode *top , int x)//压入数据 { struct Lnode *p = (struct Lnode*)malloc(sizeof(struct Lnode)); p->num = x ; p->next = top->next;//其实压入无非是链表的逆序输入,此为让新的节点指针域指向上一个节点 top->next = p; return 0; } int Pop(struct Lnode *top , int *x )//*x是为了得到弹出的数据 { struct Lnode *q; q = top->next; if( top->next != NULL )//栈不为空的时候 { *x = q->num; top->next = q->next; free(q);/*如果不释放q完全可以让p->next指向下一个,要注意的是这一步不可以跟上不颠倒,q毕竟只是指针,有指向的空间才有意义*/ return 1; } else return 0; } void convey(struct Lnode *top,int a ,int b ) { int t,i,*x,c; x=&c; while( a != 0 ) { t = a % b; Push(top,t); a = a/b; } i=1; while(i) { i=Pop(top,x); if(i) printf("%d",*x); } } void main() { int a , b; struct Lnode *top; top = (struct Lnode *) malloc (sizeof(struct Lnode)); top->next = NULL; scanf("%d%d", &a , &b); convey( top , a ,b ); }
相关文章推荐
- 菜鸟用链栈写的进制转换
- 在单链表的基础上用c++实现的链栈,并使用进制转换,表达式求值两个小程序来测试
- 单向链栈实现进制转换(十进制转换成N进制数【正数】)
- 链栈-进制转换
- 进制转换 2031(顺序 链栈)
- 小菜鸟开博啦~
- HDU 2520 我是菜鸟,我怕谁
- 菜鸟成长记-各种奇葩错误总结
- [Java从菜鸟到高手演练]之JVM内存管理及垃圾回收
- 菜鸟入门zend framework;
- 2014年2月16日 CS逍遥剑仙 开通了自己的CSDN博客 从一只无知的菜鸟向高手转变啦
- 数据结构(java语言描述)链栈的使用——表达式求值
- [Java从菜鸟到高手演练]之JVM内存管理及垃圾回收
- 菜鸟每天练习 之 图片上传
- Android菜鸟的成长笔记(13)——异步任务(Async Task)
- 菜鸟学算法之 POJ 3007 Organize Your Train part II
- c++-进制转换
- 菜鸟观comet+jquery完成简单webim项目调试过程!
- Eclipse菜鸟常用快捷键
- HDOJ 2031 进制转换