スタックとキュー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