permaculture playing cards
The moose likes C / C++ and the fly likes Typical sorting of an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Typical sorting of an array " Watch "Typical sorting of an array " New topic

Typical sorting of an array

Harshvardhan gupta

Joined: Apr 04, 2010
Posts: 8
how to sort an array in c++ using recursion but no loop ??
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46373
Same way you would do it in any language. With a recursive algorithm. Well-known examples are quicksort and merge sort.
Marek Krzeminski

Joined: Mar 13, 2011
Posts: 14

If you have stored your data in a standard template library vector you can do:

std::vector<MyObject> myArray;

myArray.push_back( new MyObject("obj1") );
myArray.push_back( new MyObject("obj3") );
myArray.push_back( new MyObject("obj2") );

std::sort( myArray.Begin(), myArray.End() );

3D OpenGL, C++ Game Development Video Tutorials @
I agree. Here's the link:
subject: Typical sorting of an array
It's not a secret anymore!