亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? nrstpath.cpp

?? 北京市交通mo+visual c++開發(fā)實例
?? CPP
字號:
#include "StdAfx.h"
#include "nrstpath.h"
#include "AppApi.h"
#include "Crack.h"
#include "Mainfrm.h"

//-----------------------------------------------------------------------------------------
CNrstPath::CNrstPath(void)
{
	m_nTimeLimit = 3;
	m_pRoutine = NULL;
	m_pRoutine = new Routine[1000];
	for(int i=0; i<1000; i++)
		m_pRoutine[i].szStaionName = NULL;
	m_pStations = NULL;
	m_pStations = new Station[5000];
	for(int i=0; i<5000; i++)
	{
		m_pStations[i].pnOrder = NULL;
		m_pStations[i].pnRoutineID = NULL;
	}
}
//-----------------------------------------------------------------------------------------
CNrstPath::~CNrstPath(void)
{
	if(m_pRoutine)
	{
		for(int i=0; i<1000; i++)
		{
			if(m_pRoutine[i].szStaionName)
			{
				delete []m_pRoutine[i].szStaionName;
				m_pRoutine[i].szStaionName = NULL;
			}
		}
		delete []m_pRoutine;
		m_pRoutine = NULL;
	}

	if(m_pStations)
	{
		for(int i=0; i<5000; i++)
		{
			if(m_pStations[i].pnOrder)
			{
				delete []m_pStations[i].pnOrder;
				m_pStations[i].pnOrder = NULL;
			}
			if(m_pStations[i].pnRoutineID)
			{
				delete []m_pStations[i].pnRoutineID;
				m_pStations[i].pnRoutineID = NULL;
			}
		}
		delete []m_pStations;
		m_pStations = NULL;
	}
}
//-----------------------------------------------------------------------------------------
void CNrstPath::Build()
{
	// 初始化m_pRoutine成員變量
	m_nRCount = BuildRoutine(m_pRoutine);
	// 初始化m_pStations成員變量
	m_nSCount = BuildStationIndex(m_pRoutine, m_nRCount, m_pStations);
}
//-----------------------------------------------------------------------------------------
short CNrstPath::BuildRoutine(Routine* pRoutine)
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CEnvironment* env = &(pMainWnd->m_environment);
	CDaoDatabase* tmpDB = new CDaoDatabase;
	try
	{
		tmpDB->Open(env->m_szDBName);
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	CDaoRecordset rs(tmpDB);
	short nCount = 0;
	short nSCount = 0;
	try
	{
		CString szSQL = "Select * from 公交車站路線 ";
		if (env->m_szBusFilter != "")
		{
			szSQL += "Where ";
			szSQL += env->m_szBusFilter;
			szSQL += " Order By 線路名";
		}
		else
			szSQL += " Order By 線路名";
		rs.Open(dbOpenDynaset, szSQL);

		CString rName;
		CString sName;
		CString sTemp1;
		CString sTemp2;
		CString* sNames = new CString[350];
		
		while(!rs.IsEOF())
		{
			COleVariant var;
			var = rs.GetFieldValue(0);
			rName = CCrack::strVARIANT(var);
			var = rs.GetFieldValue(1);
			sTemp1 = CCrack::strVARIANT(var);
			var = rs.GetFieldValue(2);
			sName = CCrack::strVARIANT(var);
			var = rs.GetFieldValue(0);
			sTemp2 = CCrack::strVARIANT(var);
            
			if(nCount == 0)
			{
				pRoutine[nCount].szRoutineName = rName;				
				if(rName.GetLength() > 4 && rName.Right(4) =="上行")
					pRoutine[nCount].nFlag = 1;
				else if(rName.GetLength() > 4 && rName.Right(4) == "下行")
					pRoutine[nCount].nFlag = 2;
				else 
					pRoutine[nCount].nFlag = 0;
				nCount++;
				nSCount = 0;
				sNames[nSCount] = sName;
				nSCount = 1;
			}
			else
			{
				if(pRoutine[nCount-1].szRoutineName == rName)
				{
					sNames[nSCount] = sName;
					nSCount++;
				}
				else
				{
					//結(jié)束上一站
					pRoutine[nCount-1].nStationNumber = nSCount;
					pRoutine[nCount-1].szStaionName = new CString [nSCount];
					for(short i=0; i<nSCount; i++)
						pRoutine[nCount-1].szStaionName[i] = sNames[i];
                    
					if(rName.GetLength() > 4 && rName.Right(4) == "上行")
						pRoutine[nCount].nFlag = 1;
					else if(rName.GetLength() > 4 && rName.Right(4) == "下行")
						pRoutine[nCount].nFlag = 2;
					else 			
						pRoutine[nCount].nFlag = 0;
					pRoutine[nCount].szRoutineName = rName;
					nCount++;
					nSCount = 0;
					sNames[nSCount] = sName;
					nSCount = 1;
				}
			}

			rs.MoveNext();
		}

		pRoutine[nCount-1].nStationNumber = nSCount;
		pRoutine[nCount-1].szStaionName = new CString [nSCount];
		for(short i=0; i<nSCount; i++)
			pRoutine[nCount-1].szStaionName[i] = sNames[i];

		delete []sNames;
		sNames = NULL;
	}
	catch (CDaoException* e)
	{
		DisplayDaoException(e);
		tmpDB->Close();
		delete tmpDB;
		e->Delete();
		return FALSE;
	}

	if(tmpDB)
	{
		if(tmpDB->IsOpen())
		{
			tmpDB->Close();
		}

		delete tmpDB;
		tmpDB = NULL;
	}
    
	return nCount;
}
//-----------------------------------------------------------------------------------------
short CNrstPath::BuildStationIndex(Routine* pAllRoutines, short nSize, Station* pStations)
{
	short nCount = 0;
	for(short i=0; i<nSize; i++)
	{
		for(short j=0; j<pAllRoutines[i].nStationNumber; j++)
		{
			short k;
			for( k=0;k<nCount;k++)
			{
				if(pStations[k].szStationName == pAllRoutines[i].szStaionName[j])
					break;
			}
			if(k == nCount)
			{
				// 添加一個新站
				pStations[k].szStationName = pAllRoutines[i].szStaionName[j];
				pStations[k].nRoutineNumber = 1;
				nCount++;
			}
			else
				pStations[k].nRoutineNumber ++;
		}
	}
	// 為各個站的信息分配內(nèi)存
	for(int i=0; i<nCount; i++)
	{
		pStations[i].pnRoutineID = new short[pStations[i].nRoutineNumber];
		pStations[i].pnOrder = new short[pStations[i].nRoutineNumber];
		pStations[i].nRoutineNumber = 0;		// 下面重新數(shù)
	}
    
	// 重新設(shè)置信息
	for(int i=0; i<nSize; i++)
	{
		for(short j=0; j<pAllRoutines[i].nStationNumber; j++)
		{
			short k;
			for(k=0; k<nCount; k++)
			{
				if(pStations[k].szStationName == pAllRoutines[i].szStaionName[j])
					break;
			}
			
			pStations[k].pnRoutineID[pStations[k].nRoutineNumber] = (short)i;
			pStations[k].pnOrder[pStations[k].nRoutineNumber] = j;
			pStations[k].nRoutineNumber ++;
		}
	}
	
	return nCount;
}
//-----------------------------------------------------------------------------------------
void CNrstPath::Search(CString sz1, CString sz2, CList<PathNode, PathNode&>* array)
{
	Search(m_pRoutine, m_nRCount, m_pStations, m_nSCount, sz1, sz2, array);
}
//-----------------------------------------------------------------------------------------
short CNrstPath::Search(Routine* pAllRoutines, short nSize, Station* pStations, 
		         short nSCount, CString szFrom, CString szTo, 
				 CList<PathNode, PathNode&>* pResPath)
{
	short nCount = 0;
	short nStationOrder;
	Node nodeCurrent  ;
	CList<Node, Node&> queueNodes;	// 存儲需要訪問的節(jié)點
	short nRoutineCurrent;
	short nStationCurrent;
	short i;
	short nMinChangeTimes=1000;		// 第一次找到的換乘次數(shù)
    
	//先得到起點站的線路
	for(i=0; i<nSize; i++)
	{
		nStationOrder = HasStation(pAllRoutines[i],szFrom,0,0);
		if(nStationOrder >= 0)
		{	
			nodeCurrent.nNodeNumber = 1;
			nodeCurrent.nRoutineOrder = new short [10];
			nodeCurrent.nStationOrder = new short [10];
            
			nodeCurrent.nRoutineOrder[0] = i;
			nodeCurrent.nStationOrder[0] = nStationOrder;
			// 入隊列操作
			queueNodes.AddTail(nodeCurrent);
		}
	}

	while(!(0 == queueNodes.GetCount()))
	{
		nodeCurrent = (Node)queueNodes.GetHead();
		queueNodes.RemoveHead();
        
		if((nodeCurrent.nNodeNumber >= m_nTimeLimit + 1) 
			|| (nodeCurrent.nNodeNumber > nMinChangeTimes-1) 
			|| (queueNodes.GetCount() > 1500000))		//換乘次數(shù)限制
			break;

		// 得到隊列頭
		// 從隊頭站點序列的最后一個站開始檢索是否能夠找到到站
		nRoutineCurrent = nodeCurrent.nRoutineOrder[nodeCurrent.nNodeNumber-1];
		nStationCurrent = nodeCurrent.nStationOrder[nodeCurrent.nNodeNumber-1];
        
		nStationOrder = HasStation( pAllRoutines[nRoutineCurrent], szTo, 
			nStationCurrent, pAllRoutines[nRoutineCurrent].nFlag);
		if(nStationOrder >= 0)  //表示找到
		{
			nodeCurrent.nRoutineOrder[nodeCurrent.nNodeNumber] = nRoutineCurrent;
			nodeCurrent.nStationOrder[nodeCurrent.nNodeNumber] = nStationOrder;
			nodeCurrent.nNodeNumber ++;

			if(nodeCurrent.nNodeNumber > nMinChangeTimes)
				break;
            
			PathNode pPathTempNode;
			pPathTempNode.nSegNumber = (short)(nodeCurrent.nNodeNumber-1);
			pPathTempNode.szRoutineName = 
				new CString[pPathTempNode.nSegNumber];
			pPathTempNode.szFromStationName = 
				new CString[pPathTempNode.nSegNumber];
			pPathTempNode.szToStationName = 
				new CString[pPathTempNode.nSegNumber];
			for(i=0; i<pPathTempNode.nSegNumber; i++)
			{
				pPathTempNode.szRoutineName[i] = 
					pAllRoutines[nodeCurrent.nRoutineOrder[i]].szRoutineName;
				pPathTempNode.szFromStationName[i] = pAllRoutines[nodeCurrent.
					nRoutineOrder[i]].szStaionName[nodeCurrent.nStationOrder[i]];
				pPathTempNode.szToStationName[i] = pAllRoutines[nodeCurrent.
					nRoutineOrder[i+1]].szStaionName[nodeCurrent.nStationOrder[i+1]];
			}
			pResPath->AddTail(pPathTempNode);
            
			if(nCount == 0)
				nMinChangeTimes = nodeCurrent.nNodeNumber;
			nCount++;
			if(nCount > 20)
				break;
		}
		else  // 要將所有可能的路徑加入隊列
		{
			for(i=(short)(nStationCurrent+1); 
				i<pAllRoutines[nRoutineCurrent].nStationNumber; i++)
			{
				CString szTheStation;
				szTheStation= pAllRoutines[nRoutineCurrent].szStaionName[i];
                
				short j = SearchStation(pStations,nSCount,szTheStation);
				for(short k=0; k<pStations[j].nRoutineNumber; k++)
				{
					short l;
					for(l=0; l<nodeCurrent.nNodeNumber; l++)
						if(pStations[j].pnRoutineID[k] == nodeCurrent.nRoutineOrder[l])
							break;
					if(l < nodeCurrent.nNodeNumber)		// 說明已經(jīng)處理過該線路
						continue;
                    
					Node nodeTemp;
					nodeTemp.nNodeNumber = (short)(nodeCurrent.nNodeNumber+1);
					nodeTemp.nRoutineOrder = new short [10];
					nodeTemp.nStationOrder = new short [10];
					for(l=0; l<nodeCurrent.nNodeNumber; l++)
					{
						nodeTemp.nRoutineOrder[l] = nodeCurrent.nRoutineOrder[l];
						nodeTemp.nStationOrder[l] = nodeCurrent.nStationOrder[l];
					}
					nodeTemp.nRoutineOrder[nodeCurrent.nNodeNumber] = 
						pStations[j].pnRoutineID[k];
					nodeTemp.nStationOrder[nodeCurrent.nNodeNumber] = 
						pStations[j].pnOrder[k];
					queueNodes.AddTail(nodeTemp);
				}
			}

			// 雙向線路,需要兩個方向查詢
			if( pAllRoutines[nRoutineCurrent].nFlag == 0 )	
			{
				for(i=(short)(nStationCurrent-1); i>=0; i--)
				{
					CString szTheStation;
					szTheStation = pAllRoutines[nRoutineCurrent].szStaionName[i];
                    
					short j = SearchStation(pStations,nSCount,szTheStation);
					for(short k=0;k<pStations[j].nRoutineNumber;k++)
					{
						short l;
						for(l=0; l<nodeCurrent.nNodeNumber; l++)
							if(pStations[j].pnRoutineID[k] ==
								nodeCurrent.nRoutineOrder[l])
								break;
						if(l < nodeCurrent.nNodeNumber)	// 說明已經(jīng)處理過該線路
							continue;
						Node nodeTemp;
						nodeTemp.nNodeNumber = (short)(nodeCurrent.nNodeNumber+1);
						nodeTemp.nRoutineOrder = new short [10];
						nodeTemp.nStationOrder = new short [10];
						for(l=0; l<nodeCurrent.nNodeNumber; l++)
						{
							nodeTemp.nRoutineOrder[l] = 
								nodeCurrent.nRoutineOrder[l];
							nodeTemp.nStationOrder[l] = 
								nodeCurrent.nStationOrder[l];
						}
						nodeTemp.nRoutineOrder[nodeCurrent.nNodeNumber] = 
							pStations[j].pnRoutineID[k];
						nodeTemp.nStationOrder[nodeCurrent.nNodeNumber] =
							pStations[j].pnOrder[k];
						queueNodes.AddTail(nodeTemp);
					}
				}
			}
		}

		if(nodeCurrent.nRoutineOrder)
		{
			delete []nodeCurrent.nRoutineOrder;
			nodeCurrent.nRoutineOrder = NULL;
			delete []nodeCurrent.nStationOrder;
			nodeCurrent.nStationOrder = NULL;
		}
	}

	int nsCount = queueNodes.GetCount();
	for(int i=0; i<nsCount; i++)
	{
		Node node = queueNodes.RemoveTail();
		delete []node.nRoutineOrder;
		node.nRoutineOrder = NULL;
		delete []node.nStationOrder;
		node.nStationOrder = NULL;		
	}
	return nCount;
}
//-----------------------------------------------------------------------------------------
// 根據(jù)站名得到它是一條公交線路上第幾站,基0,-1表示沒有
// nSearchFrom為開始搜尋的站序號
// nFlag標記向那個方向搜索,0表示雙方向,1表示單向
short CNrstPath::HasStation(Routine theRoutine, CString szStation, 
							short nSearchFrom, short nFlag)
{
	if( nFlag != 0)
	{
		for(short i=nSearchFrom; i<theRoutine.nStationNumber; i++)
			if(theRoutine.szStaionName[i] == szStation)
				return i;
	}
	else if( nFlag == 0 )
	{
		for(short i=nSearchFrom;i<theRoutine.nStationNumber;i++) // 正向搜索
			if(theRoutine.szStaionName[i] == szStation)
				return i;
		for(short i=nSearchFrom; i>=0; i--) // 反向搜索
			if(theRoutine.szStaionName[i] == szStation)
				return i;
	}
	return -1;
}
//-----------------------------------------------------------------------------------------
short CNrstPath::SearchStation(Station* pStations, short nSCount, CString theName)
{
	short j = -1;
	//用于統(tǒng)計時間
	for(j=0; j<nSCount; j++)
	{
		if(pStations[j].szStationName == theName)
		{
			return j;
		}
	}	
	return j;
}
//-----------------------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品夜夜夜夜久久| 欧美少妇bbb| 香蕉久久一区二区不卡无毒影院| 这里只有精品免费| 不卡的看片网站| 美腿丝袜一区二区三区| 亚洲人吸女人奶水| 久久久国产精品麻豆| 欧美三级韩国三级日本一级| 国产在线不卡一卡二卡三卡四卡| 午夜在线电影亚洲一区| 国产精品妹子av| 亚洲精品一线二线三线 | 成人18视频在线播放| 日韩专区一卡二卡| 亚洲综合自拍偷拍| 中文字幕在线不卡一区| 日韩精品专区在线影院重磅| 色综合激情五月| 福利一区二区在线| 麻豆久久久久久| 图片区日韩欧美亚洲| 日韩高清在线观看| 亚洲午夜久久久久久久久电影院| 日本一区二区在线不卡| 日韩一级高清毛片| 欧美疯狂性受xxxxx喷水图片| 99久久精品国产一区二区三区| 韩国精品在线观看| 麻豆精品国产传媒mv男同| 亚洲成a人在线观看| 一区二区三区久久| 亚洲黄色性网站| 亚洲色图欧洲色图婷婷| 国产精品色哟哟| 国产调教视频一区| 国产精品入口麻豆九色| 国产片一区二区| 亚洲国产精品av| 国产精品三级av在线播放| 国产欧美日韩精品a在线观看| 久久视频一区二区| 久久精品一区八戒影视| 国产日韩av一区二区| 久久综合久久久久88| 亚洲精品一区二区三区蜜桃下载 | 色中色一区二区| 色偷偷一区二区三区| 色婷婷狠狠综合| 在线视频你懂得一区| 日本高清不卡在线观看| 欧美中文字幕一区二区三区亚洲| 色综合 综合色| 欧美裸体一区二区三区| 欧美精品 日韩| 日韩精品一区二| 国产亚洲精品福利| 亚洲丝袜另类动漫二区| 亚洲免费资源在线播放| 亚洲一二三四在线| 午夜亚洲国产au精品一区二区| 石原莉奈一区二区三区在线观看| 日本三级亚洲精品| 国产在线精品一区二区夜色 | 精品国产精品网麻豆系列 | 亚洲一区二区三区四区中文字幕| 午夜久久电影网| 久久av中文字幕片| 成人性生交大合| 欧美亚洲动漫制服丝袜| 欧美一区二区三区免费视频 | www.亚洲免费av| 欧美探花视频资源| 日韩精品在线一区二区| 国产欧美一区二区三区在线看蜜臀| 国产精品视频你懂的| 亚洲一区二区美女| 九色|91porny| 91麻豆免费看| 欧美一区二区三区视频在线| 国产婷婷色一区二区三区在线| 亚洲视频免费观看| 美女视频黄 久久| 成人免费精品视频| 这里只有精品免费| 亚洲欧美中日韩| 免费成人在线播放| 91色.com| 久久色中文字幕| 五月综合激情婷婷六月色窝| 国产麻豆精品久久一二三| 日本韩国欧美在线| 国产欧美精品区一区二区三区| 亚洲一区二区精品3399| 国产成人精品免费在线| 欧美日韩aaaaaa| 亚洲四区在线观看| 国产精品一区免费视频| 欧美揉bbbbb揉bbbbb| 中文字幕一区三区| 狠狠色狠狠色合久久伊人| 日本国产一区二区| 欧美国产禁国产网站cc| 青青草原综合久久大伊人精品优势 | 国产偷v国产偷v亚洲高清| 亚洲成人1区2区| 色综合久久99| 国产精品视频免费| 国产一区久久久| 欧美成人a在线| 丝袜亚洲另类丝袜在线| 91免费看视频| 国产精品欧美综合在线| 精品一区二区三区av| 欧美写真视频网站| 亚洲欧美视频在线观看视频| 高清国产一区二区| 2023国产精品| 久久不见久久见中文字幕免费| 678五月天丁香亚洲综合网| 亚洲精选视频免费看| 成人av电影在线播放| 久久久久久久久久久99999| 美女在线一区二区| 欧美一区二区三区视频在线观看| 亚洲国产精品一区二区www在线| 91网站最新网址| 亚洲免费在线观看| 91搞黄在线观看| 亚洲综合区在线| 欧美中文字幕亚洲一区二区va在线| 国产精品毛片高清在线完整版| 国产精品系列在线观看| 久久亚洲一区二区三区明星换脸| 美女在线一区二区| 久久久久国产免费免费| 国产一区在线精品| 欧美国产日产图区| 99久久亚洲一区二区三区青草| 国产调教视频一区| 成人激情文学综合网| 中文字幕一区二| 一本色道久久综合亚洲精品按摩 | 一区二区激情视频| 欧美亚洲国产一区二区三区| 亚洲精品高清在线观看| 欧洲av在线精品| 日日骚欧美日韩| 精品久久国产97色综合| 激情综合五月天| 国产精品视频在线看| 色综合激情五月| 免费视频最近日韩| 久久久99精品免费观看不卡| 国产成人免费av在线| 国产精品国产三级国产有无不卡 | 26uuu国产日韩综合| 国产麻豆精品theporn| 成人欧美一区二区三区| 精品视频在线看| 男人操女人的视频在线观看欧美| 日韩三级视频在线观看| 国产福利精品导航| 亚洲男女毛片无遮挡| 7777精品伊人久久久大香线蕉的| 日韩不卡一区二区三区| 精品国产凹凸成av人导航| 成人免费电影视频| 亚洲不卡在线观看| 欧美电视剧在线观看完整版| 国产成人综合视频| 亚洲最新视频在线播放| 欧美一区二区三区视频免费播放| 韩国毛片一区二区三区| 中文字幕一区av| 日韩精品专区在线影院重磅| 成人动漫在线一区| 午夜精品国产更新| 国产亚洲精品7777| 欧美高清性hdvideosex| 国产电影一区在线| 午夜精品久久久久久久久| 久久午夜国产精品| 欧美日韩一卡二卡三卡| 激情图片小说一区| 亚洲午夜激情av| 国产亚洲精品久| 在线不卡欧美精品一区二区三区| 国产精品中文字幕欧美| 国产·精品毛片| 午夜精品爽啪视频| 国产精品人成在线观看免费| 91麻豆精品国产91久久久久| 成人国产精品免费观看动漫| 麻豆精品一区二区三区| 一区二区三区高清在线| 久久久不卡网国产精品二区| 欧美日本乱大交xxxxx| www.色综合.com| 国产一区二区三区免费|