发布网友 发布时间:2022-04-23 06:59
共1个回答
热心网友 时间:2022-06-17 03:50
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
char data;
struct node *next;
}linked_list;
/*void initial(linked_list *a)
{
a=(linked_list *) malloc(sizeof(linked_list));
a->next=NULL;
}*/
linked_list *create()//(linked_list *a)
{
linked_list *p,*s,*a;
char x;
int j;
a=(linked_list *) malloc(sizeof(linked_list));
a->next=NULL;
printf("\n请输入一串字符并以Q结束\n");
scanf("%c",&x);
while(x!='Q')
{
s=(linked_list *)malloc(sizeof(linked_list));
s->data=x;
if(a->next==NULL)
a->next=s;
else
p->next=s;
p=s;
scanf("%c",&x);
}
p->next=NULL;
return(a);
}
void access(struct node *a)
{
struct node *p;
p=a;
while(p->next!=NULL)
{
p=p->next;
printf(" %c\t",p->data);
}
}
main()
{
linked_list *head;
int i;
head=create();
printf("the linked list is:\n");
access(head);
}