Original Post
🔒 Locked
Sorting Vector Points
Advertisement
Quote:
Original post by Illco
Not necessarily. Standard C has quicksort also implemented, see qsort(...) in stdlib.h. You need to provide a comparison function which compares individual elements. Then qsort will sort the array accordingly.
Generally, don't use weakly-typed C standard library routines if you can. The STL is better to be used here, both because of type-safety and performance.
bool ascending_vector3_sort_predicate(const D3DXVECTOR3& lhs, const D3DXVECTOR3& rhs){ return lhs.z < rhs.z;}int main(){ D3DXVECTOR3 vecs[100]; std::sort(vecs, vecs + 101, ascending_vector3_sort_predicate); return 0;}Quote:
Original post by Illco
Good point. I thought I remembered that stl's sort worked only on stl structures (vector, array) and that red_dash was trying to avoid stl alltogether. Good that its cleared up now.
One of STL's key strengths is the concept of iterators - 'generalized' pointers of sorts. Check the great info in SGI STL documentation - read it all if you have the time (and brains! This stuff gets thick sometimes [smile]).
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement