主题:js算法(2接上)
void dispose(nodetype *h)
{
nodetype *pa=h,*pb;
if(pa!=NULL)
{
pb=pa->next;
if(pb==NULL)
free(pa);
else
{
while(pb!=NULL)
{
free(pa);
pa=pb;
pb=pb->next;
}
free(pa);
}
}
}//dispose
nodetype *sort(nodetype *h)
{
nodetype *p,*q,*t;
p=h->next;
q=p;
t=h;
count queue;
value price;
day workdays;
while(p->next!=NULL)
{
q=p->next;
while(q!=NULL)
{
if(p->price<q->price)
{
price=p->price;queue=p->queue;workdays=p->workdays;
p->price=q->price;p->queue=q->queue;p->workdays=q->workdays;
q->price=price;q->queue=queue;q->workdays=workdays;
}
else if(p->price==q->price)
{
if(p->workdays>q->workdays)
{
queue=p->queue;workdays=p->workdays;
p->queue=q->queue;p->workdays=q->workdays;
q->queue=queue;q->workdays=workdays;
}
}
q=q->next;
}
p=p->next;
}
return(t);
}
{
nodetype *pa=h,*pb;
if(pa!=NULL)
{
pb=pa->next;
if(pb==NULL)
free(pa);
else
{
while(pb!=NULL)
{
free(pa);
pa=pb;
pb=pb->next;
}
free(pa);
}
}
}//dispose
nodetype *sort(nodetype *h)
{
nodetype *p,*q,*t;
p=h->next;
q=p;
t=h;
count queue;
value price;
day workdays;
while(p->next!=NULL)
{
q=p->next;
while(q!=NULL)
{
if(p->price<q->price)
{
price=p->price;queue=p->queue;workdays=p->workdays;
p->price=q->price;p->queue=q->queue;p->workdays=q->workdays;
q->price=price;q->queue=queue;q->workdays=workdays;
}
else if(p->price==q->price)
{
if(p->workdays>q->workdays)
{
queue=p->queue;workdays=p->workdays;
p->queue=q->queue;p->workdays=q->workdays;
q->queue=queue;q->workdays=workdays;
}
}
q=q->next;
}
p=p->next;
}
return(t);
}