大佬帮帮忙,看一下,用单链表做了个学生成绩表,可是无语法错误,总出不了结果,自己改了挺久的了,沮丧,没弄出来
代码如下
#include<iostream>
#include <stdlib.h>
using namespace std;
typedef int Elemtype;
typedef struct LNode {
Elemtype score; //学生成绩
char name; //学生姓名
struct LNode *next; //指针域
}LNode;
int main()
{
struct LNode *p,*q,*head;
head=(struct LNode *)malloc(sizeof(struct LNode));
p=(struct LNode *)malloc(sizeof(struct LNode)); //怎么指针指向结点呢?????
head->next=p;
int n=6;
for(int i=0;i<n;i++)
{
q=(struct LNode*)malloc(sizeof(struct LNode)); //创建新结点
Elemtype x;
char y;
cin>>x>>y; //输入寝室505同学的成绩加姓名
q->score=x;
q->name=y;
p->next=q;
p=q;
}
q->next=NULL;
char NAME;
cin>>NAME;
struct LNode *s;
head->next=s;
while(((*s).name)!=NAME)
{
p->next=s; //注意两者顺序
p=p->next; //注意两者顺序
}
cout<<((*s).score);
return 0;
}
运行如下,就是出不了结果,本应该打印出93,可是却没反应