您的位置:首页 > 其它

题目1511:从尾到头打印链表

2015-01-31 19:29 330 查看
写的双向链表RE了,不知道肿么了,只好随手改了一个头插
#include<cstdio>
#include<cstring>
#include<cstdlib>

typedef struct node
{
	int num;
	struct node *next;
	//struct node *pre;
}SqList;

SqList *creat()
{
	SqList *p1,*p2,*temp;
	p1=(SqList *)malloc(sizeof(SqList));
	scanf("%d",&p1->num);
//	p2->next=p1;
	p2=NULL;
	p1->next=p2;
	p2=p1;
	//p2->pre=NULL;
	p1=(SqList *)malloc(sizeof(SqList));
	while(scanf("%d",&p1->num) && p1->num != -1)
	{
	//	temp=p2;
		p1->next=p2;
		p2=p1;
		p1=(SqList *)malloc(sizeof(SqList));
	}
	return p2;
}

int main()
{
	SqList *List;
	List = creat();
	while(List != NULL)
	{
		printf("%d\n",List->num);
		List=List->next;
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: