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

📄 median.c

📁 * DEFINITION * This is the header file for a library module used to calculate the median * of a
💻 C
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *  Copyright (c) 2007 by Qu chun lei watt@vip.163.com
 *
 *  File name: MEDIAN.C
 *  Module:    0603C
 *  Language:  ANSI C
 *  $Revision: 7 $
 *
 *  Source code for the median module as defined in median.h
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#ifndef MEDIAN_C
#define MEDIAN_C

#include "median.h"



/*------------*
 |  Constants
 *------------*/


/*--------------------------*
 |  Private data
 *--------------------------*/


/*------------------*
 |  Public Functions
 *------------------*/

#if MEDIAN_BIT_SIZE_32_AVAIL
/*---------------------------------------------------------------------------*
 | Median32 
 | 
 | Report the median value of a set of 32-bit numbers.
 |
 | See median.h for a further description
 *---------------------------------------------------------------------------*/

#if MEDIAN_LIST_SIZE_DYNAMIC
UINT32 Median32( UINT32 *medianArray, UINT8 medianNumberOfEntries )
#else
UINT32 Median32( UINT32 *medianArray )
#endif
{
	UINT32  median;
	UINT8  i, j, k;


#if MEDIAN_LIST_SIZE_DYNAMIC
	for  ( i = 0, k = 0; i < ( medianNumberOfEntries / 2 ) + 1; i++ )
#else
	for  ( i = 0, k = 0; i < ( MEDIAN_LIST_SIZE_MAX / 2 ) + 1; i++ )
#endif
	{						/* Set the initial median to the highest possible value */
		median  =  0xFFFFFFFF;

#if MEDIAN_LIST_SIZE_DYNAMIC
		for  ( j = 0; j < medianNumberOfEntries; j++ )
#else
		for  ( j = 0; j < MEDIAN_LIST_SIZE_MAX; j++ )
#endif
		{					/* Is this value smaller than the current median? */
			if  ( medianArray[ j ] < median )
			{					/* Yes, save the index and median */
				k  =  j;
				median  =  medianArray[ k ];
			}
		}

						/* Destroy this entry */
		medianArray[ k ]  =  0xFFFFFFFF;
	}

	return median;
}
#endif

#if MEDIAN_BIT_SIZE_16_AVAIL
/*---------------------------------------------------------------------------*
 | Median16 
 | 
 | Report the median value of a set of 16-bit numbers.
 |
 | See median.h for a further description
 *---------------------------------------------------------------------------*/

#if MEDIAN_LIST_SIZE_DYNAMIC
UINT16 Median16( UINT16 *medianArray, UINT8 medianNumberOfEntries )
#else
UINT16 Median16( UINT16 *medianArray )
#endif
{
	UINT16  median;
	UINT8  i, j, k;


#if MEDIAN_LIST_SIZE_DYNAMIC
	for  ( i = 0, k = 0; i < ( medianNumberOfEntries / 2 ) + 1; i++ )
#else
	for  ( i = 0, k = 0; i < ( MEDIAN_LIST_SIZE_MAX / 2 ) + 1; i++ )
#endif
	{						/* Set the initial median to the highest possible value */
		median  =  0xFFFF;

#if MEDIAN_LIST_SIZE_DYNAMIC
		for  ( j = 0; j < medianNumberOfEntries; j++ )
#else
		for  ( j = 0; j < MEDIAN_LIST_SIZE_MAX; j++ )
#endif
		{						/* Is this value smaller than the current median? */
			if  ( medianArray[ j ] < median )
			{						/* Yes, save the index and median */
				k  =  j;
				median  =  medianArray[ k ];
			}
		}

							/* Destroy this value */
		medianArray[ k ]  =  0xFFFF;
	}

	return median;
}
#endif

#if MEDIAN_BIT_SIZE_8_AVAIL
/*---------------------------------------------------------------------------*
 | Median8 
 | 
 | Report the median value of a set of 8-bit numbers.
 |
 | See median.h for a further description
 *---------------------------------------------------------------------------*/

#if MEDIAN_LIST_SIZE_DYNAMIC
UINT8 Median8( UINT8 *medianArray, UINT8 medianNumberOfEntries )
#else
UINT8 Median8( UINT8 *medianArray )
#endif
{
	UINT8  median;
	UINT8  i, j, k;


#if MEDIAN_LIST_SIZE_DYNAMIC
	for  ( i = 0, k = 0; i < ( medianNumberOfEntries / 2 ) + 1; i++ )
#else
	for  ( i = 0, k = 0; i < ( MEDIAN_LIST_SIZE_MAX / 2 ) + 1; i++ )
#endif
	{						/* Set the initial median to the highest possible value */
		median  =  0xFF;

#if MEDIAN_LIST_SIZE_DYNAMIC
		for  ( j = 0; j < medianNumberOfEntries; j++ )
#else
		for  ( j = 0; j < MEDIAN_LIST_SIZE_MAX; j++ )
#endif
		{						/* Is this value smaller than the current median? */
			if  ( medianArray[ j ] < median )
			{						/* Yes, save the index and median */
				k  =  j;
				median  =  medianArray[ k ];
         }
		}

							/* Destroy this entry */
		medianArray[ k ]  =  0xFF;
	}

	return median;
}
#endif


#endif

⌨️ 快捷键说明

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