004
28.04.2008, 17:31 Uhr
xXx
Devil
|
Hmm naja da ne Klasse draus zu machen ist doch mist
C++: |
template<typename _Iter> struct sort_algortihm { sort_algorithm(iterator_type ptr_first, iterator_type ptr_last) : m_first(ptr_first), m_last(ptr_last) {}
void operator()() { sort(m_first, m_last); }
protected: inline void sort(iterator_type, iterator_type);
protected: _Iter m_first; _Iter m_last; typedef _Iter iterator_type; typedef typename std::iterator_traits<iterator_type>::value_type value_type; };
template<typename _Iter> struct quick_sort : public sort_algorithm<_Element> { quick_sort(iterator_type ptr_first, iterator_type ptr_last) : sort_algorithm(ptr_first, ptr_last) {}
void operator()() { sort(); }
private: void sort(iterator_type it_first, iterator_type it_last) { if (it_first != it_last) { iterator_type it(std::partition(it_first, it_last, std::bind2nd(std::less<value_type>(), *it_first)); if (it != it_last) sort(it_first, it); if (it != it_first) sort(it, it_last); else sort(++it, it_last); } } };
|
so sollte das aber gehen
C++: |
int arr[] = {0, 1, 2, 3, 5, 1, 3, 7, 0 }; quick_sort(arr, arr + (sizeof(arr) / sizeof(arr[0])))();
|
|