添加节点有问题。怎么改正?谢谢!

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:37:01
代码:

#include "stdafx.h"
#include "iostream"
#include "string"

using namespace std;
struct test
{
char name[10];
float socre;
test *next;
};

test *head;

test *create()
{
test *ls;
test *le;
ls=new test;

head=NULL;
le=ls;

while(strcmp(ls->name,"null")!=0)
{
le=ls;
ls=new test;
cin>>ls->name>>ls->socre;
if(head==NULL)
{
head=ls;
}
else{
le->next=ls;
}

}

le->next=NULL;
delete ls,le;
return head;
}

void showl(test *head)
{
cout<<"the first point:"<<head<<endl;
while(head)
{
cout<<head->name<<"|"<<head->socre<<endl;
head=head->next;
}
}

怎么又是你呀,呵呵,你看看这样行不?再出现问题要加分了噢^_^

void add(int pa)
{
cout<<"Enter the name and number:"<<endl;
test *test1;
test1=new test;
cin>>test1->name>>test1->socre;
if(pa==1)
{
test1->next=head;
head=test1;
}
else
{
int t=0;
test *ps,*qs;
ps=head;
while(ps->next!=NULL)
{
t++;
ps=ps->next;
}
if(t>pa)
{
ps=head;
for(int i=2;i<pa;i++)
{
ps=ps->next;
}
qs=ps->next;
ps->next=test1;
test1->next=qs;
}
else
{
ps->next=test1;
test1->next=NULL;
}
}
}

这句是什么意思using namespace std; ?