大虾帮帮忙看看啊!!这个链表程序有问题!(C)

来源:百度知道 编辑:UC知道 时间:2024/05/09 19:26:01
正在学数据结构,自己写了一个有关链表基本操作的程序,可是在运行时却运行一半就退出了,不知问题出在哪里,请各位看看啊~~
#include <stdio.h>
#include <stdlib.h>
/*定义链表结点*/
typedef struct node
{ int data;
struct node *link ;
}LNode;
/*函数声明*/
LNode *CreateList(int m);
LNode *LocateNode(LNode *p,int x);
LNode *InsertNode(LNode *head,int a,int b);
void DeleteNode(LNode *h,int x );
void DisplayList();
/*主函数*/
main ()
{LNode*L;
int i,j,a,e,x,y;
printf("==================================\n");
printf ("| 链表的基本操作: |\n");
printf ("| 1. 建立并输出链表 |\n");
printf ("| 2. 插入结点并输出链表 |\n");
printf ("| 3. 删除结点并输出链表 |\n");
printf ("| 4. 查找结点并输出 |\n");
printf ("| 5. 退出 |\n");
printf ("=================================\n");
p

这是我当年做的,你看看对你有没有帮助!
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define chN 10 //读取菜单输入时的多余字符
#define NameLength 20 //名字占用多少字节长
typedef float datatype;
typedef struct LNode //定义结点
{ char name[NameLength]; //名字
datatype score; //分数
struct LNode *next; //指向下一个结点的指针
}LinkList;

LinkList *NewList()
{ LinkList *head;
head=(LinkList *)malloc(sizeof(LinkList));
//生成头结点head
head->next=NULL;
head->score=(-0.01); //方便进行判断
return (head); // 返回单链表的头指针
}

void ContinueList(LinkList *head)
{ LinkList *p,*q,*r; //p.q为工作指针;r为新增节电
r=(LinkList *)malloc(sizeof(LinkList));
//开辟新节点空间
printf("-------NEW-------\n");
printf("Name:");
gets(r->name); //输入名字
printf("Score:");
while(1) //输入数据合法性检查
{ scanf("%f",&r->score);