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

📄 pgpinsertionsort.h

📁 vc环境下的pgp源码
💻 H
字号:
/*____________________________________________________________________________
	Copyright 1991 Lloyd Chambers
	Rights granted to PGP to use this source code freely and
	without restriction.

	This file should be #included, and the following symbols defined:
	
	InsertionSortName
	InsertionSortItem
	
	For example:
	#define InsertionSortName	MySortName
	#define InsertionSortItem	MyStructName
	#include "pgpInsertionSort.h"
	#undef InsertionSortName
	#undef InsertionSortItem
	
	$Id: pgpInsertionSort.h,v 1.2 1997/09/17 00:45:42 mhw Exp $
____________________________________________________________________________*/


/*____________________________________________________________________________
	This function is declared static on purpose. Place it in a C file and
	write a wrapper if you want to make it visible.
____________________________________________________________________________*/
	static void
InsertionSortName(
	InsertionSortItem		*start,
	size_t					numItems,
	int 					(*compareProc)( InsertionSortItem *item1,
								InsertionSortItem *item2, void *userValue ),
	void *					userValue )
{
	InsertionSortItem		*stop;
	InsertionSortItem		*cur;
	InsertionSortItem		*least;
	InsertionSortItem		data;
	InsertionSortItem		temp;
	
	if ( numItems <= 1 )
		return;
	stop	= start + (numItems - 1);
	
	/*
	** find least element and place it at start so
	** we can guarantee halt to insertion
	*/
	least = cur = start;
	do
	{
		++cur;
		if ( compareProc( cur,least, userValue ) < 0 )
			least = cur;
	} while ( cur < stop );
	/* swap */
	temp	= *least;
	*least	= *start;
	*start	= temp;
	
	while ( start < stop )
	{
		++start;	/*  next item to insert */
		cur = start;
		
		data = *start;
		
		while ( compareProc( &data, cur - 1, userValue ) < 0 )
		{
			*cur	= *(cur - 1);
			--cur;
		}
		*cur	= data;
	}
}



⌨️ 快捷键说明

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