不带头结点的单链表的建立

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gaohuaid/article/details/10241859
#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;
}


展开阅读全文

没有更多推荐了,返回首页