为什么在链表中间插入节点插入不了啊
#include<stdio.h>
#include<stdlib.h>
typedef struct xs {
int xh;
char xm[15];
struct xs *jdzz;
} xs; // 结构体
xs *tjd() {
xs *p = NULL;
p = (xs *) malloc(sizeof(xs));
p->jdzz = NULL;
return p;
} // 创建首节点并传给main
void sjd(xs * js) {
xs *czz; // 创建节点指针
int i, gs; // 循环变量和录入个数变量
printf(" 输入个数\n");
scanf("%d", &gs);
printf("学号 姓名\n");
for (i = 0; i < gs; i++) {
czz = (xs *) malloc(sizeof(xs)); // 通过循环创建多个节点
scanf("%d", &czz->xh);
scanf("%s", &czz->xm);
czz->jdzz = NULL; // 录入并把指针指空
js->jdzz = czz; // main函数里的指针指向头节点
js = czz;
}
}
void dy(xs * p) {
while (p->jdzz != NULL) {
p = p->jdzz;
printf("%d %s\t", p->xh, p->xm);
}
}
void tzj(xs * p) {
xs *k = (struct xs *)malloc(sizeof(xs));
printf("\n请输入头部新增学员\n");
scanf("%d", &k->xh);
scanf("%s", &k->xm);
k->jdzz = p->jdzz;
p->jdzz = k;
return 0;
}
void wzj(xs * p) {
xs *k = (xs *) malloc(sizeof(xs));
printf("\n输入尾部要添加的学员\n"); // 动态节点创建
scanf("%d", &k->xh);
scanf("%s", &k->xm); // 录入数据域
k->jdzz = NULL; // 指针域指空
while (1) // 循环移动p指针找到最后节点
{
p = p->jdzz; // 移动实现
if (p->jdzz == NULL) // 空指针判断
{
p->jdzz = k; // 找到尾节点后让尾节点指向新建节点
break;
}
}
return 0;
}
void zjcr(xs * p) {
xs *k = (xs *) malloc(sizeof(xs));
int i;
printf("\n请问插入哪里? ");
scanf("%d", &i);
printf(" \n请输入插入学员信息");
scanf("%d", &k->xh);
scanf("%s", &k->xm);
while (1) {
p = p->jdzz;
if (p->xh == i) {
k->jdzz = p;
p = k;
break;
}
}
}
int main() {
xs *p;
p = tjd();
sjd(p);
dy(p);
tzj(p);
dy(p);
wzj(p);
dy(p);
zjcr(p);
dy(p);
free(p);
return 0;
}