Skip to content

Commit

Permalink
added SGVector method for qsort
Browse files Browse the repository at this point in the history
added a method to find index where to insert element into sorted vector
  • Loading branch information
karlnapf committed Jun 7, 2012
1 parent 631c3e7 commit b6e2afd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/shogun/mathematics/Math.h
Expand Up @@ -1188,6 +1188,35 @@ class CMath : public CSGObject
}
}

/** For a sorted (ascending) vector, gets the index after the first
* element that is smaller than the given one
*
* @param vector vector to find position in
* @param element element to find index for
* @return index of the first element smaller than given one plus 1
*/
template <class T>
static index_t find_position_to_insert(SGVector<T> vector, T element)
{
index_t i;
for (i=0; i<vector.vlen; ++i)
{
if (vector[i]<element)
break;
}
return ++i;
}

/** performs a quicksort on the given vector
* it is sorted from in ascending (for type T)
*
* @param vector vector to sort
*/
template <class T>
static void qsort(SGVector<T> vector)
{
qsort(vector.vector, vector.vlen);
}

/** performs a quicksort on an array output of length size
* it is sorted from in ascending (for type T) */
Expand Down

0 comments on commit b6e2afd

Please sign in to comment.