二进制转换为十进制|栈和队列
发布日期:2021-05-07 06:43:44 浏览次数:18 分类:精选文章

本文共 1012 字,大约阅读时间需要 3 分钟。

#include 
#include
#include
#define STACK_INIT_SIZE 20#define STACKINCERMENT 10typedef char ElemTypetypedef struct { ElemType *top; ElemType *base; int stackSize;}sqstack;void InitStack(sqStack *s){ s->base = (ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType)); if(!s->base) { exit(0); } s->top = s->base; s->stackSize = STACK_INIT_SIZE;}void Push(sqStack *s,ElemType e){ if(s->top - s->base >= s->stackSize) { s->base = (ElemType*)realloc(s->base,s->stackSzie+STACKINCERMENT); if(!s->base) { exit(0); } s->top = s->base + s->stackSize; stackSize += STACKINCERMENT; } *(s->top) = e; s->top++;}void Pop(sqStack *s,ElemType e){ if(s->top == s->base) { return; } *e = *--(s->top);}int StackLen(sqStack s){ return s.top - s.base;}int main(){ ElemType c; sqStack s; int len, i, sum=0; InitStack(&s); printf("请输入二进制数,以#符号结束!\n"); scanf("%c",&c); while(c!='#') { Push(&s,c); scanf("%c",&c); } getchar(); //把'\n'从缓冲区去掉 len = StackLen(s); for(i=0;i
上一篇:惠普 Qt5无法调用F1帮助文档的解决办法
下一篇:使用SQL Sever Management Studio 注释|数据库

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月01日 21时30分53秒