立即学习:https://edu.csdn.net/course/play/1566/24180?utm_source=blogtoedu
创建一个链表的节点
struct node* create_node(int data)
{
struct node* p = (struct node*)malloc(sizeof(struct node));
if(p == NULL)
{
return NULL;
}
bzero(p,sizeof(struct node));
p->data = data;
p->pNext = NULL;
return p;
}
struct node* pHead = create_node(1);
pHead->pNext = create_node(2);
pHead->pNext->pNext = create_node(3);
插入节点,头部插入节点
void insert_tail(struct node* pH,struct node* new)
{
struct node *p = pH;
while(p->pNext != NULL)
{
p = p->pNext;
}
p->pNext = new;
}
使用过程
struct node* pH = create_node(1);
insert_tail(pH,create_node(2));
insert_tail(pH,create_node(3));
insert_tail(pH,create_node(4));