void LocateNode(DLinkList *&L, ElemType x)

1140 ワード

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
",p,p->data,p->freq,p->next); //getchar(); t = p->next; if(x == p->data) { //printf("2,%p,%d f:%d next,%p
",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
",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; } }