为什么我的线性链表不能插入节点数据也写不进去数据
#include <stdio.h>
#include <stdlib.h>
//结构体类型
typedef struct snode
{
int name;
int asdf;
}link_node;
//链表结点类型
typedef struct node
{
link_node data;
struct node *next;
}linknode;
//创建链表
linknode *create_empty_linklist()
{
linknode *head = NULL;
head = (linknode *)malloc(sizeof(linknode));
head->next = NULL;
return head;
}
//判断链表是否为空
int is_empty_linlist(linknode *head)
{
return head->next == NULL;
}
//头插法,在头节点之后插入
int insert_head_liklist(linknode *head,int name,int asdf)
{
linknode *temp = NULL;
temp = (linknode *)malloc(sizeof(linknode));
temp->data.name = name;
temp->data.asdf = asdf;
temp->next = head->next;
return 0;
}
//链表输出
int print_linklist(linknode *head)
{
linknode *p = head->next;
while(p)
{
printf("%d%d",p->data.name,p->data.asdf);
p = p->next;//找到尾0->next
}
printf("\n");
return 0;
}
//删除节点
int delete_assign_linklist(linknode *head,int data)
{
linknode *temp = NULL;
linknode *p = head;
temp = (linknode *)malloc(sizeof(linknode));
while(p->next)
{
if (p->next->data.name == data)
{
break;
}
p = p->next;
}
temp = p->next;
p->next = temp->next;
free(temp);
temp = NULL;
return 0;
}
//主函数
void main()
{
linknode *head = create_empty_linklist();
//插入三个节点
insert_head_liklist(head,1,2);
insert_head_liklist(head,2,4);
insert_head_liklist(head,5,6);
print_linklist(head);
system("pause");
}
...全文
相关推荐
线性链表的插入与删除
本文档是对线性链表进行插入删除操作的代码,包含了两个不同的程序。用户可以对比参看。
线性链表的实现(c语言)
能实现线性链表的建立插入删除,移动等功能的完整c语言的代码
数据结构实验三-有关线性链表的操作_数据结构实验三-有关线性链表的操作_
数据结构实验三-有关线性链表的操作,建立线性链表,初始化线性链表,插入元素,删除元素,清空线性链表,摧毁线性链表
不带表头结点的线性链表的实现
不带表头结点的线性链表的实现 源代码 实现以下功能:1、生成线性表 2、显示线性表 3、在线性表中插入一个数据 4、在线性表中删除一个数据 5、退出
数据结构:线性链表的表示以及实现(C语言编写)
数据结构:线性链表的表示以及实现(C语言编写) 有完整的代码注释以及重点分析


