aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Typical sorting of an array " Watch "Typical sorting of an array " New topic
Author

Typical sorting of an array

Harshvardhan gupta
Greenhorn

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

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

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 @
www.marekKnows.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Typical sorting of an array