冒泡排序

来源:互联网 发布:电棒在淘宝上怎么说 编辑:程序博客网 时间:2024/06/08 08:18

 

/* 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

原创粉丝点击