#include <stdio.h>
#include <stdlib.h>
struct yo {
int data;
struct yo *next;
};
int main() {
struct yo *head,*p,*q,*s,*r;
p=(struct yo*)malloc(sizeof(struct yo));
p->data=1;
head=p;
q=(struct yo*)malloc(sizeof(struct yo));
q->data=20;
p->next=q;
s=(struct yo*)malloc(sizeof(struct yo));
s->data=30;
q->next=s;
s->next=NULL;
r=(struct yo*)malloc(sizeof(struct yo)); //插入r节点
r->data=10; //将r节点数据域写入数
r->next=p->next; //插头:head=r; //插尾:r->next=null
p->next=r; //r->next=p; // s-next=r;
struct yo *x; //
x=head;
while(x!=NULL) { //遍历链表数据
printf("%d\n",x->data);
x=x->next;
}
return 0;
}
在单链表中插入节点
最新推荐文章于 2023-05-23 10:14:11 发布