线性表练习题2-4

时间:2021-08-18 00:15:02
 
#include<iostream>
using namespace std;

int LocateNode(DLinkList *h,ElemType x)
{
	DLinkList *p=h->next,*q;
	while(p!=NULL&&p->data!=x)
		p=p->next;
	if(p==NULL)
		return 0;
	else
	{
		p->freq++;
		q=p->prior;
		while(q!=h&&q->freq<p->freq)
		{
			p->prior=q->prior;
			p->prior->next=p;
			q->next=p->next;
			if(q->next!=NULL)
				q->next->prior=q;
			p->prior=q;
			q->next=p;
			q=p->next;
		}
		return 1;
	}
}