为什么我的线性链表不能插入节点数据也写不进去数据

屈工智能科技 CSDN会员 屈工智能科技 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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");
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
屈工智能科技 CSDN会员
C++ 语言 65,214 成员 250,514 内容