主题:初学者C++求助
要做一个简单的工资管理程序,
要求按工资顺序排练链表
我按书上的编,但是输入第1个数据就出错,调试时指向
"if(phead->pDate->dlSalary>=newrec->pDate->dlSalary)"错误
以下是函数,求达人解答(最好能留下QQ:))
void CList::insert_node(CNode * phead,CNode *newrec)
{
CNode *p1,*p2;
if(phead=NULL){
newrec->next = NULL;
phead = newrec;
}
if(phead->pDate->dlSalary>=newrec->pDate->dlSalary)
{
newrec->next = phead;
phead = newrec;
}
p2=p1=phead;
while(p2->next&&p2->pDate->dlSalary<newrec->pDate->dlSalary)
{
p1=p2;p2=p2->next;
}
if(p2->pDate->dlSalary<newrec->pDate->dlSalary)
{
p2->next=newrec;newrec->next=0;
}
else{
newrec->next=p2;p1->next=newrec;
}
phead=phead->next;
}
要求按工资顺序排练链表
我按书上的编,但是输入第1个数据就出错,调试时指向
"if(phead->pDate->dlSalary>=newrec->pDate->dlSalary)"错误
以下是函数,求达人解答(最好能留下QQ:))
void CList::insert_node(CNode * phead,CNode *newrec)
{
CNode *p1,*p2;
if(phead=NULL){
newrec->next = NULL;
phead = newrec;
}
if(phead->pDate->dlSalary>=newrec->pDate->dlSalary)
{
newrec->next = phead;
phead = newrec;
}
p2=p1=phead;
while(p2->next&&p2->pDate->dlSalary<newrec->pDate->dlSalary)
{
p1=p2;p2=p2->next;
}
if(p2->pDate->dlSalary<newrec->pDate->dlSalary)
{
p2->next=newrec;newrec->next=0;
}
else{
newrec->next=p2;p1->next=newrec;
}
phead=phead->next;
}