nodetype *js(nodetype *h)
{
    nodetype *p=h->next,*s,*t,*r,*h0=NULL;
    bool flag;

    h0=(nodetype *)malloc(sizeof(nodetype));
    h0->queue=0;h0->workdays=0;h0->price=0;h0->next=NULL;

    while(p->next!=NULL)
    {
        s=(nodetype *)malloc(sizeof(nodetype));
        s->queue=p->queue;s->price=p->price;s->workdays=p->workdays;s->next=NULL;

        if(locate1(h,p)==1)
            h0->next=s;
        else
        {
            t=h0->next;
            while(t->next!=NULL)
            {if(s->workdays>=t->workdays)
                    t=t->next;
            else   break;}
          if((t->next==NULL)&&(t->workdays<=s->workdays)&&(s->workdays>=locate1(h0,t)+1))
                      t->next=s;   //尾部插入
        else if((t->next==NULL)&&(t->workdays<=s->workdays)&&(s->workdays<locate1(h0,t)+1))
         {free(s);break;}     //continue   //尾部不能插入,退出循环p=p->next
         else if(t->next!=NULL) //中间插入
        {r=t;
           while(r->next!=NULL)
            if(r->workdays>locate1(h0,r))
                r=r->next;
            else
            {flag=false;break;}
            if(r->workdays>locate1(h0,r))
                flag=true;
        }
            if(flag==false)
            {free(s);continue;}
            else
            {s->next=t;locate2(h0,t)->next=s;}
        }
    p=p->next;
    }    
    
//    if((t->workdays<=p->workdays)&&(p->workdays>=locate1(h0,t)+1))
//     t->next=p;p->next=NULL;
//    if((t->workdays<=p->workdays)&&(p->workdays<locate1(h0,t)+1))
         //free(p);
return(h0);
}    


void main()
{
    nodetype *p,*q;
    p=create();
    cout<<"输入单链表为:"<<endl;
    print();
    disp(p);
    p=sort(p);
    cout<<"排序后结果为:"<<endl;
    print();
    disp(p);
    q=js(p);
    cout<<"JS有限期排序后结果为:"<<endl;
    print();
    disp(q);
    dispose(p);
    dispose(q);
    //p=sort(p);
//    disp(p);
}