previous | start | next

1.2 Convert this to valid C++ code:

#ifndef SIMPLESORT_H
#define SIMPLESORT_H

template <class T>
void simplesort(T a[], int n)
{
  int maxpos;
  for(int i = n; i > 1; i--) {
    maxpos = 0;
    for(int j = 1; j < i; j++) {
      if ( a[maxpos] < a[j] ) {
        maxpos = j;
      }
    }
    T tmp = a[maxpos];
    a[maxpos] = a[i-1];
    a[i-1] = tmp;
  }
}
#endif



previous | start | next