#include
#include
typedef struct list_node
{
char data;
struct list_node *next;
}linklist;
linklist *cr
#include
#include
typedef struct list_node
{
char data;
struct list_node *next;
}linklist;
linklist *creatlist_rear() //尾插入法建立单链表
{
char ch;
linklist *head,*s,*r;
head=NULL;
r=NULL;
ch=getchar();
while(ch!='#')
{
s=(linklist *)malloc(sizeof(linklist));
s->data=ch;
if(head==NULL)
{
head=s;
}
else
{
r->next=s;
}
r=s;
ch=getchar;
}
if(r!=NULL)
{
r->next=NULL;
}
return head;
}
void displaynode(linklist *head) //打印链表里的数据
{
linklist *p=head;
int j=1;
while(p!=NULL)
{
printf("]c
",j,p->data);
p=p->next;
j ;
}
}
void deletememory(linklist *head) //释放链表里的数据
{
linklist *p=head,*pr=NULL;
while(p!=NULL)
{
pr=p;
p=p->next;
free(pr);
}
}
int main()
{
int i=0;
linklist *head=NULL;
printf("请输入数据,按井号键结束
");
head=creatlist_rear();
displaynode(head);
deletememory(head);
}
展开
全部