14栈和队列的应用-数制的转换

#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;
}
发布了24 篇原创文章 · 获赞 0 · 访问量 81

猜你喜欢

转载自blog.csdn.net/qq_45812941/article/details/104413592