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;
}
}
void LocateNode(DLinkList *&L, ElemType x)
最新推荐文章于 2024-09-15 20:19:31 发布