This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 40490
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 @
Consider Paul's rocket mass heater.
subject: Typical sorting of an array