线性表练习题2-4

#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;
	}
}


原文地址:https://www.cnblogs.com/riskyer/p/3226016.html