#include<stdio.h>
#include<stdlib.h>
int main(void)
{
struct linklist
{
int data;
struct linklist* next;
};
struct linklist *top,*base;
struct linklist* p;
int n;
scanf_s("%d", &n);
getchar();
top = (struct linklist*)malloc(sizeof (struct linklist));
base = top;
p = top;
while (1)
{
top->data = n % 2;
n = n / 2;
if (top == base)
{
base->next = NULL;
p = top;
}
else
{
top->next = p;
p = top;
}
if (n == 0)
break;
top= (struct linklist*)malloc(sizeof(struct linklist));
}
while (1)
{
printf("%d", top->data);
if (top == base)
break;
top = top->next;
}
return 0;
}
14栈和队列的应用-数制的转换
原创
©著作权归作者所有:来自51CTO博客作者高万禄的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:15栈和队列的应用-回文的判定
下一篇:13链队列
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java面试算法题:如何使用栈去实现队列
java面试算法题:如何使用栈去实现队列
出队 入栈 时间复杂度 -
解决「问题」,不要解决问题
够解决
程序员 软件产品 阅读器 -
数制转换与子网划分
数制转换与子网划分
数制 子网