数据结构单链表程序错误,请大家帮忙看看该怎么改?
程序要求单链表的建立,查找,插入和删除,除了main函数是我自己写的以外的函数都是直接抄了书上的,但因为自己C语言没学好,所以程序有很多问题,目前程序上没有语法问题,但运行到查找时就没办法继续下去了,自己调试了很多遍也不知道该怎么去改,希望有人能帮我看看该怎么改,最好能告诉我原因在哪,非常感谢!#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define FALSE 0
#define TRUE 1
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode, *Linklist;
void CreateListR(Linklist L)
{
int x; Linklist p;
L = (Linklist)malloc(sizeof (LNode));
p = L;
scanf_s("%d", &x);
while (x != -999)
{
p->next = (Linklist)malloc(sizeof (LNode));
p = p->next;
p->data = x;
scanf_s("%d", &x);
}
p->next = NULL;
}
void CreatelistF(Linklist L)
{
int x; Linklist s;
L = (Linklist)malloc(sizeof (LNode));
L->next = NULL;
scanf_s("%d", &x);
while (x != -999)
{
s = (Linklist)malloc(sizeof (LNode));
s->data = x;
s->next = L->next; L->next = s;
scanf_s("%d", &x);
}
}
Linklist Locate(Linklist L, ElemType item)
{
Linklist p;
printf_s("%d", &p);
p = L->next;
while (p&&p->data != item)
{
p = p->next;
}
if (!p) return NULL;
else return (p);
}
int Insert(Linklist L, int i, ElemType item)
{
Linklist p, s; p = L;
int j = 0;
while (p&&j<i - 1)
{
p = p->next; ++j;
}
if (!p || j>j - 1) return FALSE;
s = (Linklist)malloc(sizeof (LNode));
s->data = item;
s->next = p->next; p->next = s;
return TRUE;
}
int Delete(Linklist L, int i)
{
Linklist q, p;
int j;
q = L; j = 0;
while (q&&j<j - 1)
{
q = q->next; ++j;
}
if (!q || j>i - 1) return FALSE;
p = q->next;
q->next = p->next;
free(p);
return TRUE;
}
int main()
{
LNode student;
printf("尾插法请输入学号:");
CreateListR(&student);
printf_s("---------------------------\n");
printf_s("头插法请输入学号:");
CreatelistF(&student);
printf_s("----------------------------\n");
int i;
ElemType x;
printf("请输入要查找的学号:");
scanf_s("%d", &x);
Locate(&student, x);
printf("请输入要插入的学号位置:");
scanf_s("%d", &i);
printf_s("请输入要插入的学号:");
scanf_s("%d", &x);
Insert(&student, i, x);
printf("请输入要删除的学号位置:");
scanf_s("%d", &x);
Delete(&student, x);
system("pause");
return 0;
}