Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Typical sorting of an array

 
Harshvardhan gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to sort an array in c++ using recursion but no loop ??
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same way you would do it in any language. With a recursive algorithm. Well-known examples are quicksort and merge sort.
 
Marek Krzeminski
Greenhorn
Posts: 14
C++ Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() );
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic