typedef struct dnode20
{
int data, fre;
dnode20 *lnext, *rnext;
}Dnode20;
void printDnode20(Dnode20 *h)
{
Dnode20 *p = h->rnext;
while (p)
{
printf("%d fre:%d ", p->data, p->fre);
p = p->rnext;
}
}
Dnode20 *createDnode20link()//创建20题目要求的链表
{
type x;
Dnode20 *h, *t;
t = h = (Dnode20 *)malloc(sizeof(Dnode20));
h->rnext=h->lnext = NULL;
scanf_s("%d", &x);
while (x != -1)
{
Dnode20 *s = (Dnode20 *)malloc(sizeof(Dnode20));
s->data = x;
s->fre = 0;
s->rnext = NULL;
t->rnext = s;
s->lnext = t;
t = s;
scanf_s("%d", &x);
}
t->rnext = NULL;
printDnode20(h);
return h;
}
Dnode20 *Locate20(Dnode20 *h,type x)
{
Dnode20 *p=h;
Dnode20 *q,*m;
while (p->rnext&&p->rnext->data != x)
p = p->rnext;
if (!p->rnext)
return NULL;
++(p->rnext->fre);
q = p;
m = p->rnext;
p->rnext = m->rnext;
if (m->rnext!=NULL)
m->rnext->lnext = p;
while (q!= h&&q->fre <= m->fre)
q = q->lnext;
q->rnext->lnext = m;
m->rnext = q->rnext;
m->lnext = q;
q->rnext = m;
/*q->rnext->lnext = m;
p->rnext = m->rnext;
m->lnext = q;
if (m->rnext)
m->rnext->lnext = p;
m->rnext = q->rnext;
q->rnext = m;*/
}