quicksort algorithm

Hi,

I wrote a quicksort algorithm that takes two RandomAccessIterators and sorts the array. The function definition is like:-

template<typename _RandomAccessIterator>
void quicksort(_RandomAccessIterator __first, _RandomAccessIterator __last);

I tried to test it with vector<int>.

I call my algorithm with
quicksort(the_vector.begin(), the_vector.end())

I see that __last variable points to a memory location that is one more than the end of the vector. i.e If I declare a vector of size 10 like vector<int> the_vector(10), __last points to the eleventh element. For a vector<int> the_vector(2), __last points to the 3rd element.

I can modify my algorithm to handle this. But is it true for all container classes? like, will map.end() point to a memory location that is more than the actual map size?

Eagerly waiting for your replies.
Yes. However, the call doesn't make for all containers. For example, std::maps and std::sets are always sorted.
Topic archived. No new replies allowed.