quicksort

This commit is contained in:
Joachim Schoeberl 2009-10-28 00:22:10 +00:00
parent 94a06d8cae
commit 20c2f2757e
3 changed files with 55 additions and 55 deletions

View File

@ -612,8 +612,8 @@ namespace netgen
template <class T, class S> template <class T, class S>
void QickSortRec (FlatArray<T> & data, void QuickSortRec (FlatArray<T> & data,
FlatArray<T> & slave, FlatArray<S> & slave,
int left, int right) int left, int right)
{ {
int i = left; int i = left;
@ -633,14 +633,14 @@ namespace netgen
} }
} }
while (i <= j); while (i <= j);
if (left < j) QickSortRec (data, slave, left, j); if (left < j) QuickSortRec (data, slave, left, j);
if (i < right) QickSortRec (data, slave, i, right); if (i < right) QuickSortRec (data, slave, i, right);
} }
template <class T, class S> template <class T, class S>
void QickSort (FlatArray<T> & data, FlatArray<S> & slave) void QuickSort (FlatArray<T> & data, FlatArray<S> & slave)
{ {
QickSortRec (data, slave, 0, data.Size()-1); QuickSortRec (data, slave, 0, data.Size()-1);
} }

View File

@ -16,9 +16,9 @@
namespace netgen namespace netgen
{ {
void Sort (const Array<double> & values, void Sort (const Array<double> & values,
Array<int> & order) Array<int> & order)
{ {
int n = values.Size(); int n = values.Size();
int i, j; int i, j;
@ -32,13 +32,13 @@ void Sort (const Array<double> & values,
{ {
Swap (order.Elem(j), order.Elem(j+1)); Swap (order.Elem(j), order.Elem(j+1));
} }
} }
void QickSortRec (const Array<double> & values, void QuickSortRec (const Array<double> & values,
Array<int> & order, Array<int> & order,
int left, int right) int left, int right)
{ {
int i, j; int i, j;
double midval; double midval;
@ -58,18 +58,18 @@ void QickSortRec (const Array<double> & values,
} }
} }
while (i <= j); while (i <= j);
if (left < j) QickSortRec (values, order, left, j); if (left < j) QuickSortRec (values, order, left, j);
if (i < right) QickSortRec (values, order, i, right); if (i < right) QuickSortRec (values, order, i, right);
} }
void QickSort (const Array<double> & values, void QuickSort (const Array<double> & values,
Array<int> & order) Array<int> & order)
{ {
int i, n = values.Size(); int i, n = values.Size();
order.SetSize (n); order.SetSize (n);
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
order.Elem(i) = i; order.Elem(i) = i;
QickSortRec (values, order, 1, order.Size()); QuickSortRec (values, order, 1, order.Size());
} }
} }

View File

@ -14,7 +14,7 @@ namespace netgen
extern void Sort (const Array<double> & values, extern void Sort (const Array<double> & values,
Array<int> & order); Array<int> & order);
extern void QickSort (const Array<double> & values, extern void QuickSort (const Array<double> & values,
Array<int> & order); Array<int> & order);