⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chaosenumerator.cpp

📁 基于com的网络爬虫程序
💻 CPP
字号:
//
// This file is part of UniWebSpider Project.
//
// UniWebSpider is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// UniWebSpider is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with UniWebSpider; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

// WRITTEN BY	: ValGarn

// ChaosEnumerator.cpp: implementation of the CChaosEnumerator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ChaosEnumerator.h"
#include "math.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

typedef CChaosEnumerator* pCChaosEnumerator;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CChaosEnumerator::CChaosEnumerator()
{
	m_p = 0;
	m_pNext = 0;
	m_pHead = this;
}

CChaosEnumerator::CChaosEnumerator( void* p )
{	
	m_p = p;
	m_pNext = 0;
	m_pHead = this;
}

CChaosEnumerator::~CChaosEnumerator()
{
}

void CChaosEnumerator::Rock()
{	
	CChaosEnumerator* pCE1 = m_pHead;
	CChaosEnumerator* pCE2 = 0;

	for(long n=0; pCE1 && (pCE1->m_p != 0); n++ )
	{
		CChaosEnumerator* pCE = new CChaosEnumerator( pCE1 );
		pCE->m_pNext=pCE2;
		pCE2=pCE;
		pCE1=pCE1->m_pNext;
	}
	pCE1 = m_pHead;

	srand( (unsigned)time( NULL ) );    
	for(long i=0; i<n; i++)
	{
		long n1=(long)floor(n*rand()/RAND_MAX);
		long n2=(long)floor(n*rand()/RAND_MAX);

		void* p1=pCE1;
		for(long j=0; j<n1; j++) p1=pCChaosEnumerator(p1)->m_pNext;

		void* p2=pCE2;
		for(j=0; j<n2; j++) p2=pCChaosEnumerator(p2)->m_pNext;

		void* tmp=pCChaosEnumerator(pCChaosEnumerator(p2)->m_p)->m_p;
		pCChaosEnumerator(pCChaosEnumerator(p2)->m_p)->m_p = pCChaosEnumerator(p1)->m_p;
		pCChaosEnumerator(p1)->m_p = tmp;
	}
}

void** CChaosEnumerator::GetArray()
{
	CChaosEnumerator* pCE = m_pHead;
	for(long i=0; pCE->m_p && ++i && pCE->m_pNext; ) pCE=pCE->m_pNext;
	void** ar = new void*[i+1];
	pCE = m_pHead;
	ar[i] = 0;
	while(i) 
	{
		ar[--i]=pCE->m_p;
		pCE=pCE->m_pNext;
	}
	Rock();
	return ar;
}

bool CChaosEnumerator::Add( void* p )
{
	CChaosEnumerator* pCurrentCE = m_pHead;
	if(pCurrentCE->m_p == 0) 
	{
		pCurrentCE->m_p = p;
		return true;
	}
	while(pCurrentCE->m_pNext && (pCurrentCE->m_p != p)) 
						pCurrentCE = pCurrentCE->m_pNext;
	if(pCurrentCE->m_p == p) return false;
	CChaosEnumerator* pCE = new CChaosEnumerator( p );
	pCurrentCE->m_pNext = pCE;
	pCurrentCE->m_pHead = m_pHead;
	Rock();
	return true;
}

bool CChaosEnumerator::Delete( void* p )
{
	CChaosEnumerator* pCurrentCE = m_pHead;
	CChaosEnumerator* pLast = 0;
	while(pCurrentCE->m_pNext)
	{
		if(pCurrentCE->m_p == p && pCurrentCE->m_pNext)
		{
			pCurrentCE->m_p=pCurrentCE->m_pNext->m_p;
			pCurrentCE->m_pNext->m_p=p;			
		}
		pLast = pCurrentCE;
		pCurrentCE = pCurrentCE->m_pNext;
	}	
	if(pCurrentCE->m_p!=p) return false;
	if(pCurrentCE != m_pHead)
	{
		delete pCurrentCE;
		pLast->m_pNext=0;
	}
	else pCurrentCE->m_p=0;
	Rock();
	return true;
}

bool CChaosEnumerator::IsExists( void* p )
{
	CChaosEnumerator* pCurrentCE = m_pHead;
	while(pCurrentCE->m_pNext && (pCurrentCE->m_p != p)) 
								pCurrentCE = pCurrentCE->m_pNext;
	bool bResult = (pCurrentCE->m_p == p)?true:false;
	Rock();
	return bResult;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -