// $Id: sort.h,v 1.1.1.1 2000/11/02 08:47:17 fritzi Exp $ // This file is part of the DEAL Library // DEAL is Copyright(1995) by // Roland Becker, Guido Kanschat, Franz-Theo Suttmeier #ifndef __sort_h #define __sort_h ////////// template inline void swap(T* a, T* b) { T x = *a; *a = *b; *b = x; } ////////// template inline void simple_sort(long n, T* field) { long i,j; for (i=1;i inline void heapsort_sift(T* a, long l, long r) { long i = l; long j = 2*i; T x = a[i]; while (j<=r) { if (j inline void heapsort(int n, T* field) { field--; long l =(n/2)+1; long r = n; while (l>1) { l--; heapsort_sift(field,l,r); } while (r>1) { swap(field+l,field+r); r--; heapsort_sift(field,l,r); } } ////////// template inline void quicksort(long r, T* a, long l = 1) { long i = l; long j = r; T* x = &a[(l+r)/2]; do { while (a[i] < *x) i++; while (*x < a[j]) j--; if (i<=j) { swap(a+i,a+j); i++; j--; } } while (i<=j); if (l