void LocateNode(DLinkList *&L, ElemType x)

void LocateNode(DLinkList *&L, ElemType x)
{    DLinkList *p = L->next, *t,*a,*b,*c;
    while(p !=NULL)
    {    //printf("1,%p,%d f:%d next,%p\n",p,p->data,p->freq,p->next);
        //getchar();
        t = p->next;
        if(x == p->data)
        {    //printf("2,%p,%d f:%d next,%p\n",p,p->data,p->freq,p->next);
            ++p->freq;
            while(p!=L->next && p->freq > p->prior->freq)//error
            {    //printf("3,%p,%d f:%d next,%p\n",p,p->data,p->freq,p->next);    
                a = p->prior->prior;
                b = p->prior;
                c = p->next;
                if(a!=NULL)
                {    a->next = p;
                    p->prior = a;
                }
                else break;
                p->next = b;
                b->prior = p;
                b->next = c;
                if(c!=NULL)c->prior = b;
                p = a->next;//move to right            
            }                
        }
        p = t;
        
    }

}


你可能感兴趣的:(Data_Structure)