怎么将原有的链表放在一个新链表中就不行了???
#include<iomanip.h>#include<iostream.h>
#include<conio.h>
struct student
{ long num;
float score;
student *next;
};
student *Creat() ( 创建新链表 按学号 从小到大链接)
{ student *h,*q,*p,*k,*d;
h=NULL;p=new student;
q=p;
cout<<"\ninput num and score\n";
cin>>p->num>>p->score;
while(p->num>0&&p->score>0)
{ if(h==NULL)
{ h=p;
q=p;
k=h;
}
else
{ if(p->num>=q->num)
{q->next=p;
q=p;
}
if(p->num<q->num)
{ if(p->num<k->num)
{ p->next=k;
h=p;
k=h;
}
else
{ while(p->num>k->num)
{ d=k;
k=k->next;
}
p->next=k;
d->next=p;
k=h;
}
}
}
p=new student;
cout<<"\nInput num and score\n";
cin>>p->num>>p->score;
}
q->next=NULL;
return h;
}
void print( student *h) (输出链表)
{ student *p;
p=h;
do
{ cout<<endl<<p->num<<"\t"<<p->score<<endl;
p=p->next;
}while(p!=NULL);
}
student *Good( student *h) (把成绩过85的重新放在一个链表中,求救这里哪里错了,因为我是一步一步做的前面和主函数都没问题,当我加了这个函数后却发现不是输出的结果)
{ student *L,*p,*q,*k;
L=NULL;
q=new student;
p=h;
while(p!=NULL)
{ if(L==NULL&&p->score>=85)
{ q->num=p->num; cout<<"\nq->num="<<q->num;
q->score=p->score; cout<<"\nq->score="<<q->score; (这几个输出是我用来查错的,就只是知道这里有错,不知哪错了,事实也没做完,但这里出了问题也做不下去了)
L=q;
k=q;
}
if(L!=NULL&&p->score>=85)
{ q->num=p->num; cout<<"\nq->num="<<q->num;
q->score=p->score; cout<<"\nq->score"<<q->score;
k->next=q;
k=q;
}
p=p->next;
q=new student;
}
return L;
}
int main()
{ student *head,*st; char ch;
do
{ clrscr();
head=Creat();
print(head);
st=Good(st);
ch=getch();
cout<<"Continue()?"<<endl;
}while(ch!='n');
return 0;
}
真心求教大神啊