您的位置:首页 > 其它

链表 头插法,尾插法

2015-07-13 15:23 260 查看
<span style="font-family:SimSun;font-size:18px;">/*#include <stdio.h>
#include <stdlib.h>
struct Node//链表的尾插法
{
char date;
Node *next;
};
int main()
{
Node *p,*q,*x,*head;
char c;
p=(Node *)malloc(sizeof(Node));
p->next=NULL;
head=p;
while(scanf("%c",&c))
{
if(c=='\n')
break;
q=(Node *)malloc(sizeof(Node));
q->date=c;
p->next=q;
p=p->next;
}
p->next=NULL;
x=head->next;
while(x!=NULL)
{
printf("%c",x->date);
x=x->next;
}
printf("\n");
return 0;

}*/
#include <stdio.h>
#include <stdlib.h>
struct Node//链表的头插法
{
char date;
Node *next;
};
int main()
{
Node *p,*q,*x,*head;
char c;
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
while(scanf("%c",&c))
{
if(c=='\n')
break;
p=(Node *)malloc(sizeof(Node));
p->date=c;
p->next=head->next;
head->next=p;
}
q=head->next;
while(q!=NULL)
{
printf("%c",q->date);
q=q->next;
}
printf("\n");
return 0;
}</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: