帮忙修改一下这个程序(在编译时不能通过)

来源:百度知道 编辑:UC知道 时间:2024/05/30 21:27:41
数据结构单链表应用:编写一个完整的C++语言程序,输入信息:学生的学号,姓名
完成功能:
1.创建一个空白链表
2.可以动态的插入学生信息,并保持按学号递减顺序排列
3.随时查询学生信息(按学号)
4.随时删除学生信息
5.显示所有学生信息

-------------
请选择
1.插入
2.查询
3.删除
4.显示所有

程序如下:
#include<iostream.h>
#include<string.h>
class student{
char *name;
int xh;
student *next;

}
student *head;//首指针
//-------输入-------
student *getInput()
{
student *newnode;
int x;
char *name1;
cout<<"请输入学号:";cin>>x;
cout<<"请输入姓名:";
cin>>name1;
name1=new char[strlen(name1)+1];
strcpy(name,name1);

newnode->name=name;
newnode->xh=x;
newnode->next=null;

return newnode;
}
void *getsuru(student *head,student *newnode1)
{
student *q,*p;
if(head->next!=NULL)
{
q=head;
p=head->next;

写的不知所云,细节错误全部帮你改了,没有运行,我估计运行也是一堆问题.
还有...你的函数类型的声明和调用...写的很...无语

建议你一句一句的调试,错误很多,那个输入地方帮你改过来了
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
string name;
int xh;
student *next;
};
class student *head;//首指针
//-------输入-------
student *getInput()
{
student *newnode;
newnode = new student;
int x;
string name1, name;
cout<<"请输入学号:";cin>>x;
cout<<"请输入姓名:";
cin>> name1;
// name1=new char[strlen(name1)+1];
name = name1;

newnode->name=name;
newnode->xh=x;
newnode->next=NULL;

return newnode;
}
void getsuru(student *head,student *newnode1)
{
student *q,*p;
if(head->next!=NULL)
{
q=head;
p=head->next;
while(p!=NULL&&p->xh<newnode1->xh)