Go to the documentation of this file.00001
00021 #ifndef SORT_H
00022 #define SORT_H
00023
00024 #include "RZ.h"
00025 #include <cstdlib>
00026
00027 void quickSort(vector<RZ> &vec, int begin, int end) {
00028
00029 if(begin < end) {
00030
00031 int left = begin - 1;
00032 int right = end + 1;
00033
00034
00035 int pivot = (end - begin - 1) + begin;
00036 int pivotVal = vec.at(pivot).getRZCost();
00037
00038 while(1) {
00039 do right--; while(vec.at(right).getRZCost() > pivotVal);
00040 do left++; while(vec.at(left).getRZCost() < pivotVal);
00041
00042 if(left < right) {
00043
00044 RZ rztmp(vec.at(left));
00045 vec[left] = vec.at(right);
00046 vec[right] = rztmp;
00047 } else break;
00048 }
00049
00050
00051 quickSort(vec, begin, right);
00052 quickSort(vec, right + 1, end);
00053 }
00054 }
00055
00056 #endif