线性表练习题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;
	}
}


posted on 2013-07-30 19:13  you Richer  阅读(148)  评论(0编辑  收藏  举报