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

📄 route_guide_sort.c

📁 道路导航系统程序
💻 C
字号:
/***************************************************************************
	FileName      :	     route_guide_sort.c

	Date          :	     2006.04.09

	Author        :	     QZYTM Developing Group

	Content       :      Route Guide System Sort Proc

	Copyright     :	     QZYTM-GROUP @ SIST_S0527
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Modify History
	NO       Date           Modifier         Modified Content

****************************************************************************/

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*																		   */
/*                        Include File Section                             */
/*																		   */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include "route_guide_s.h"
#include "route_guide_in_c.h"
#include "route_guide_in_s.h"
#include "route_guide_in_p.h"
#include "route_guide_common.h"

/*-------------------------------------------------------------------------*/
/*																		   */
/*   Function Definition Section                                           */
/*																		   */
/*-------------------------------------------------------------------------*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

int Part(S_LNKTBL a[] , int begin , int end)
{
	int low = begin ;   
	int high = end  ;
	int temp = low;
    /* Sort proc												*/
	while(low < high )			
	{
		/*Find LinkID Size */
		while(a[high].stLnkTblRec.udwLinkID  >=a[temp].stLnkTblRec.udwLinkID   && low< high)
		{
			high-- ;
		}
			/* Temporary buffer	set									  */
		memcpy( &a[low], &( a[high].stLnkTblRec ), 
				    sizeof( S_LNKTBL_REC ) );

		while(a[low].stLnkTblRec.udwLinkID <=a[temp].stLnkTblRec.udwLinkID   && low < high)
		{
			low++ ;
		}
		memcpy( &a[high], &( a[low].stLnkTblRec), 
				    sizeof( S_LNKTBL_REC ) );
	
	}
	memcpy( &a[low].stLnkTblRec, &( a[temp].stLnkTblRec), 
				    sizeof( S_LNKTBL_REC ) );
	
	return low ;
}

/*++++++++++++++++quick sort method++++++++++++++++++++++++++*/
void QuickSort(S_LNKTBL a[] , int begin ,int end )
{
	int position ;
	if(begin>=end)
	{
		return ;
	}
	else
	{
		position = Part(a,begin,end);
		QuickSort(a,begin,position-1) ;
		QuickSort(a,position+1 , end) ;
	}
}
/*+++++++++++start the sort ++++++++++++++++++++++++++++++++++++*/
STATUS SelectSort(
	S_LNKHEADER*     ptrRecHeader
	)
{
	S_LNKTBL*        ptrRecArray    = NULL;
	S_LNKTBL*        ptrLoopNode    = ptrRecHeader->pNxtNode;
	UDWORD           udRecNum       = ptrRecHeader->udwNumOfRecs;
	UDWORD           udTempCnt      = 0;
	UDWORD           udCurCnt       = 0;
	UDWORD           udTimeCnt      = 0;
	UDWORD           udStoreMin     = 0;
    /*  Link node allocation					*/
	ptrRecArray 
		= ( S_LNKTBL* )malloc( udRecNum * sizeof( S_LNKTBL ) );
   /* Link node read buffer initialization				*/
	if ( ptrRecArray == NULL )
	{
		return RET_FAILED;
	}

	printf( "System is now sorting the route data.Please Wait ." );
    /*******************************/
	while ( ptrLoopNode != NULL )
	{
		memcpy( &ptrRecArray[ udTempCnt ], ptrLoopNode,
			    sizeof( S_LNKTBL ) );
		udTempCnt++;
		ptrLoopNode = ptrLoopNode->pNxtNode;
		
	}
    QuickSort(ptrRecArray,0,udRecNum-1  ) ;
   /********************get the LinkNode********************/
	for ( udCurCnt = 0; udCurCnt < udRecNum - 1; udCurCnt++ )
	{
		ptrRecArray[ udCurCnt ].pNxtNode = &ptrRecArray[ udCurCnt + 1 ];
	}
    /************* Get the node**********************************/ 
	ptrRecHeader->pNxtNode = &ptrRecArray[ 0 ];
	ptrRecHeader->pTailNode = &ptrRecArray[ udRecNum - 1 ];

	return RET_SUCCESS;
}
 


/*+++++++++++++++delete the link ++++++++++++++++++++++++++++++++++++++++*/
STATUS DeleteRecArray( 
	S_LNKHEADER      strRecHeader 
	)
{
	S_LNKTBL*        ptrCurLnk  = strRecHeader.pNxtNode;
    /****delete  the LinkNode********/
	free( strRecHeader.pNxtNode );
	strRecHeader.pNxtNode = NULL;
	strRecHeader.pTailNode = NULL;

	return RET_SUCCESS;
}

/*++++++++++Output the result into file++++++++++++++++++++++++++++*/
STATUS OutPutSortFile( 
	S_LNKHEADER      strRecHeader,
	FILE*            ptrFilePointer
	)
{
	/* save the node header*/
	S_LNKTBL*        ptrRouteRec = strRecHeader.pNxtNode ;

	printf( "\nWriting to File..." );

	if ( ptrFilePointer == NULL )
	{
		/*delete the linkNode*/
		DeleteRecArray( strRecHeader );
		fclose( ptrFilePointer );
		return RET_FAILED;
	}
/******write the every node *****************/ 
   //ptrRouteRec = ptrRouteRec->pNxtNode ; 
	while ( ptrRouteRec != NULL )
	{
	
		fwrite( ptrRouteRec->stLnkTblRec.pvRtLnk, 
			    ptrRouteRec->stLnkTblRec.uwRecSize,
			    1, 
				ptrFilePointer );
		
		ptrRouteRec = ptrRouteRec->pNxtNode; 
	}

 /***************close the file*********/
	fclose( ptrFilePointer );

	return RET_SUCCESS;
}



⌨️ 快捷键说明

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