询编程高手解答,重谢!

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:16:52
帮忙看看次程序的错误,谢谢O(∩_∩)O哈哈~
抱歉,刚才忘记弄了
#include<stdio.h>
#include<malloc.h>
typedef struct LNode
{
int no; //学号 取值范围1-99
int score; //成绩 取值范围0-100
struct LNode *next;
}LNode, *LinkList;

int InitList(LinkList &L);
int InsertList(LinkList L, int no, int score);
int ShowList(LinkList L);
void main()
{
LinkList L;
int i, no, score;
for (i=0; i<10; i++)
{
scanf("%d,%d",&no,&score);
InsertList(L, no, score);
}

ShowList(L);

}

int InitList(LinkList &L)
{ /* 操作结果:构造一个空的线性表L */
L=(LinkList)malloc(sizeof(struct LNode)); /* 产生头结点,并使L指向此头结点 */
if(!L) /* 存储分配失败 */
return 1;
L->next=NULL; /* 指针域为空 */
return 0;
}
int InsertList(LinkList L;x;y)
{
p.no=x;
p.score=y;
p=p->next;

修改如下,注意程序中的标记位置:

//---------------------------------------------------------------------------

#include<stdio.h>
#include<malloc.h>
typedef struct LNode
{
int no;
int score;
struct LNode *next;
}LNode, *LinkList;

int InitList(LinkList L);
LinkList InsertList(LinkList L,int x,int y); /*注意这里*/
int ShowList(LinkList L);
void main()
{
LinkList L=NULL;
int i, no, score;
for (i=0; i<10; i++)
{
scanf("%d%d",&no,&score); /*注意这里,输入数据时用空格或者回车分隔*/
L=InsertList(L, no, score); /*注意这里*/
}

ShowList(L);

}

int InitList(LinkList L) /*此函数无用*/
{
L=(LinkList)malloc(sizeof(struct LNode));
if(!L)
return 1;
L->next=NULL;
return 0;
}
LinkList InsertList(LinkList L,int x,int y) /************重点,特别注意这里*/
{
if (L==NULL) {
L=malloc(sizeof(LNode));
L->no=x;