//ChoiceSort.h
/*
filename: ChoiceSort.h
author:
description: Choice sort functions
date: 20130113
All Rights Reserved
*/
#ifndef CHOICE_SORT_H_
#define CHOICE_SORT_H_
#ifdef __cplusplus
extern "C"
{
#endif
//#include "..\..\Shared\App\CommonMecroFun.h"
#ifndef TYPE_DEFINE_
#define TYPE_DEFINE_
typedef unsigned long ULONG32;
typedef long LONG32;
typedef signed long SLONG32;
typedef unsigned int UINT32;
typedef int INT32;
typedef signed int SINT32;
typedef unsigned short UINT16;
typedef short INT16;
typedef signed short SINT16;
typedef enum SortOrder_
{
eUpOrder, // up order 升序排列
eDownOrder, //down order 降序排列
}eSortOrder;
/*
if *Low < *High, and return eUpOrder, up order will be
if *Low < *High, and return eDownOrder, down order will be
if *Low > *High, and return eUpOrder, down order will be
if *Low > * High, and return eDownOrder, up order will be
*/
typedef eSortOrder (*Order)(void* Low, void* High);
typedef enum SortStatus_
{
eSortNullPt,// Null pointer
eSortZeroNum,//the number of source is 0, no data to sort
eSortZeroSize,//the size of member is 0, error
eSortOK,//para is OK
}eSortStatus;
typedef struct Array_
{
UINT32 Num; //the members of a array //数组成员的数目
UINT32 Size; //the size of a member,in byte //数组成员的大小,以字节为单位
void * BaseAddr; //the beginnig address of a array //数组的开始地址
}Array;
UINT32 Num = 0;//the number of members of a array
UINT32 Size = 0; //the size of a member of a array
void* BaseAddr = NULL;//the base address of array
//check para
eSortStatus eStatus = eSortNullPt;
eStatus = ChkChoiceSortPara(pAryProperty);
if(eStatus != eSortOK)
{
return (eStatus);
}
Num = pAryProperty->Num;
Size = pAryProperty->Size;
BaseAddr = pAryProperty->BaseAddr;
//sort
for(i=0; i
{
MoreLittleOrBigIdx = i;
for(j=MoreLittleOrBigIdx+1; j
{
// find the more less or bigger data
if(eDownOrder == SortOrder(VOID_PT_ADD_INT(BaseAddr, Size*MoreLittleOrBigIdx), VOID_PT_ADD_INT(BaseAddr, Size*j)))
{
MoreLittleOrBigIdx = j;
}
}
if(MoreLittleOrBigIdx != i)// if we find the more less or bigger data, then swap it and array
{
StrNSwap(VOID_PT_ADD_INT(BaseAddr, Size*i), VOID_PT_ADD_INT(BaseAddr, Size*MoreLittleOrBigIdx), Size);
}
}