Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Typical sorting of an array

 
Harshvardhan gupta
Greenhorn
Posts: 8
  • 0
  • 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
Pie
Posts: 47293
52
  • 0
  • 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
  • 0
  • 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() );
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic