std::sort() should work:
CArray<int> arrayOfInts; arrayOfInts.Add(7); arrayOfInts.Add(114); arrayOfInts.Add(3); std::sort(arrayOfInts.GetData(), arrayOfInts.GetData()+arrayOfInts.GetSize());
This uses the pointer to the first element in the array as the start iterator, and the pointer to the last one last element as the last iterator (should never be dereferenced anyway, so all is well). You can also pass a custom predicate if the array contains more interesting data:
struct Foo { int val; double priority; }; bool FooPred(const Foo& first, const Foo& second) { if ( first.val < second.val ) return true; if ( first.val > second.val ) return false; return first.priority < second.priority; }
Oh - and do not use CArray .
Shog9
source share