数据结构链栈
//链栈
#include<stdio.h>
#include<malloc.h>
struct node{
	int data;
	struct node *next;
};
main()
{
	struct node *top,*p,*q;
	int x;
	scanf("%d",&x);
	top=(struct node *)malloc(sizeof(struct node));			//产生一个节点
	top->next=NULL;
	printf("\n%d=",x);
while(x!=0)			//入栈
{
	p=(struct node *)malloc(sizeof(struct node));		//产生节点
	p->data=x%2;
	p->next=top->next;		//现在的节点指向top后的元素
	top->next=p;			
	x=x/2;
}
while(top->next!=NULL)
{
	q=top->next;
	printf("%d",q->data);
	
	top->next=q->next;
	free(q);
}
printf("\n");
}
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634994.html

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号