不带头结点的单链表的建立
程序员文章站
2024-03-21 13:32:28
...
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct LinkList_
{
int data;
struct LinkList_ *next;
}LinkList;
void create_list(LinkList **list)
{
int data;
LinkList *new_node;
data = getchar();
if(data != '#');
if( NULL == (*list = (LinkList *)malloc(sizeof(LinkList))) )
exit(-1);
(*list)->data = data - '0';
(*list)->next = NULL;
while((data = getchar()) != '#')
{
if( NULL == (new_node = (LinkList *)malloc(sizeof(LinkList))) )
exit(-1);
new_node->data = data - '0';
new_node->next = (*list)->next;
(*list)->next = new_node;
}
}
int main()
{
LinkList *list;
create_list(&list);
free(list);
return 0;
}
上一篇: 不带头结点的链表的建立和打印