人蠢是硬伤,╮(╯▽╰)╭,想了一下午终于理解了
#include<stdio.h>
#include<stdlib.h>
struct ac
{
int x,y;
struct ac *next;//理解为屁股
}*fuz,*head;//定义辅助指针 和 头指针
void Union(int a,int b)//<strong>导入数据</strong>
{
ac *p;
p=(struct ac *)malloc(sizeof(struct ac));//敲出空间,链入数据
p->x=a;
p->y=b;
p->next=NULL;
fuz->next=p;//当前的下一个是p
fuz=p;//辅助指针永远指向链表的尾部 图解head0--------》p--》p---0fuz
}
void print()//<strong>输出函数</strong>
{
ac *sb;
sb=head;//指向头 头相当于地址(门牌)
while(sb->next!=NULL)
{
sb=sb->next;//开门拿数据
printf("%d %d\n",sb->x,sb->y);
}
}
int main()
{
int x,y;
head=(ac *)malloc(sizeof(ac));
head->next=NULL;
fuz=head; //辅助指针永远都是链表的尾
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&x,&y);
Union(x,y);
}
print();
}