/* FUNCTION_BEG *****************************************************
函数名: TBubbleSort
功能: 冒泡排序
算法:
实现: Snight Q:51171107
FUNCTION_END ******************************************************/
#ifndef H_BUBBLESORT_H
#define H_BUBBLESORT_H
/* 正序 */
template <class T>
int TBubbleSortP(T* apArray, unsigned long aulSize);
/* 逆序 */
template <class T>
int TBubbleSortR(T* apArray, unsigned long aulSize);
/****** Achieve ******/
template <class T>
int TBubbleSortP(T* apArray, unsigned long aulSize)
{
if ((NULL == apArray) || (aulSize <=0))
return 0;
T loTempObj;
for (unsigned long i = 0; i < aulSize; ++i)
{
for(unsigned long j = 0; j< aulSize;++j)
{
if (apArray[i] < apArray [j])
{
loTempObj = apArray[i];
apArray[i] = apArray[j];
apArray[j] = loTempObj;
}
}
}
return 1;
}
template <class T>
int TBubbleSortR(T* apArray, unsigned long aulSize)
{
if ((NULL == apArray) || (aulSize <=0))
return 0;
T loTempObj;
for (unsigned long i = 0; i < aulSize; ++i)
{
for(unsigned long j = 0; j< aulSize;++j)
{
if (apArray[i] > apArray [j])
{
loTempObj = apArray[i];
apArray[i] = apArray[j];
apArray[j] = loTempObj;
}
}
}
return 1;
}
#endif//H_BUBBLESORT_H