C语言问题...帮忙在

来源:百度知道 编辑:UC知道 时间:2024/06/05 15:12:00
输入一个字符串建立链表,每个结点保存一个字符,然后复制该链表并输出

什么叫复制链表?能说的具体一些吗?将已经建好的原链表重头到尾输出?
你看看这个程序符不符合你的要求
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define NULL 0
struct z
{
char a;
struct z *next;
};
void main( )
{
int i;
struct z *head,*p,*q;
char s[80];
printf("输入字符串:");
gets(s);
for(i=0;i<strlen(s);i++)
{

q=(struct z *)malloc(sizeof(struct z));
if(i==0) head=p=q;
q->a=s[i];
p->next=q;
p=q;
}
p->next=NULL;
p=head;
printf("输出链表:");
while(p!=NULL)
{
printf("%c ",p->a);
p=p->next;
}
}