Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __XN_ALGORITHMS_H__
00023 #define __XN_ALGORITHMS_H__
00024
00025
00026
00027
00028 #include <XnPlatform.h>
00029
00030
00031
00032
00033 template<class T>
00034 XnBool DefaultComparer(const T& arg1, const T& arg2)
00035 {
00036 return arg1 < arg2;
00037 }
00038
00039 class XnAlgorithms
00040 {
00041 public:
00042 template<class T, class Comparer>
00043 static void BubbleSort(T elements[], XnUInt32 nCount, Comparer comp)
00044 {
00045 XnUInt32 n = nCount;
00046 XnBool bSwapped;
00047 T temp;
00048
00049 if (nCount == 0)
00050 return;
00051
00052 do
00053 {
00054 bSwapped = FALSE;
00055 for (XnUInt32 i = 0; i < n - 1; ++i)
00056 {
00057 if (!comp(elements[i], elements[i+1]))
00058 {
00059
00060 temp = elements[i];
00061 elements[i] = elements[i+1];
00062 elements[i+1] = temp;
00063
00064 bSwapped = TRUE;
00065 }
00066 }
00067
00068 n -= 1;
00069
00070 } while (bSwapped);
00071 }
00072
00073 template<class T>
00074 static void BubbleSort(T elements[], XnUInt32 nCount)
00075 {
00076 BubbleSort(elements, nCount, DefaultComparer);
00077 }
00078
00079 };
00080
00081 #endif // __XN_ALGORITHMS_H__