BCGSN 2022-11-23 21:34 采纳率: 80%

为什么插入和删除后的链表输出不了？

我想要达到的结果
``````#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#define ERROR 0
#define OK 1

typedef struct Stu_Node {
char name[20];
int number;
float score;
struct Stu_Node* next;
//初始化
{
L->next = NULL;
return L;
}
//头插
{
Stu_Node* s;
int flag = 1;
char name[20];
int number;
float score;

while (flag)
{

printf("请输入学生信息：");
scanf("%s %d %f", &name, &number, &score);
if (name != '\$' && number != 0 && score != 0)
{
s = (Stu_Node*)malloc(sizeof(Stu_Node*));
strcpy(s->name, name);
s->number = number;
s->score = score;
s->next = L->next;
L->next = s;
}
else flag = 0;
}
}

//查找
//查找第i个结点,
{
Stu_Node* p;
int j = 1;
p = L;
while (p->next != NULL && j < i)
{
p = p->next;
j++;
}
if (i == j)
{
printf("你要查找的学生信息为：姓名：%s 学号：%d 成绩：%f\n", p->name, p->number, p->score);
}
else
return NULL;
}
//查找值等于key的结点
{
Stu_Node* p;
p = L->next;
while (p != NULL)
{
if (p->number != number)
p = p->next;
else
break;
printf("你要查找的学生信息为：姓名：%s 学号：%d 成绩：%f\n", p->name, p->number, p->score);
}

}
//插入
int InsList(LinkList L, int i, char name, int number, float score)
{
Stu_Node* pre, * s;
int k;
pre = L;
k = 0;
while (pre != NULL && k < i - 1)
{
pre = pre->next;
k++;
}
if (k != i - 1)
{
printf("插入的位置不合理");
return ERROR;
}
s = (Stu_Node*)malloc(sizeof(Stu_Node*));
strcpy(s->name, name);
s->number = number;
s->score = score;
s->next = pre->next;
pre->next = s;
return OK;
}
//删除
int DelList(LinkList L, int i, char *name,int *number,float *score)
{
Stu_Node* p, * r;
int k;
p = L;
k = 0;
while (p->next != NULL && k < i - 1)
{
p = p->next;
k++;
}
if (k != i - 1)
{
printf("删除结点的位置i不合理");
return ERROR;
}
r = p->next;
p->next = p->next->next;
*name = r->name;
*number = r->number;
*score = r->score;
free(r);
return OK;
}
//求链表长度
{
Stu_Node* p;
p = L->next;
int j = 0;
while (p != NULL)
{
p = p->next;
j++;
}
printf("学生的总人数为%d", j);
return j;
}

//输出
{
printf("学生链表的内容为：\n");
printf("姓名 学号 成绩\n");
L = L->next;
while (L != NULL)
{

printf("%s %d %f\n", L->name, L->number, L->score);
L = L->next;
}

}

int main()
{
int i;
int x;
char name;
int number;
float score;
char *name1=NULL;
int *number1=NULL;
float *score1=NULL;
L = InitList(L);

printf("头插法创建学生链表\n");
Printlist(L);

printf("请输入要查询学生的序号:");
scanf("%d", &i);
Get(L,i);

printf("请输入要查询的学生的学号:");
scanf("%d", &number);
Locate(L,number);

printf("请输入要插入的位置及要插入的学生信息：");
scanf("%d %s %d %f", &x, &name, &number, &score);
InsList(L, x, name, number, score);
Printlist(L);

printf("请输入要删除的学生序号及信息：");
scanf("%d &s %d %f",&i,&name, &number,&score);
DelList(L, i, name1, number1, score1);
Printlist(L);

ListLength(L);

}

``````
• 写回答

• 创建了问题 11月23日

悬赏问题

• ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
• ¥20 OpenCV-Python简单轮廓寻找
• ¥20 使用matlab进行含参数的最优化求解及数值模拟
• ¥20 MATLAB找出一维变量中的局部极大值和局部极小值，并进行运算
• ¥15 有Chang求三维杆单元几何非线性分析matlab代码
• ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
• ¥50 pyinstaller 打包问题
• ¥15 无法使用cnssc调取网页数据
• ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错
• ¥15 Python社区划分