• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Typical sorting of an array

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to sort an array in c++ using recursion but no loop ??
 
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
C++ Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() );
 
reply
    Bookmark Topic Watch Topic
  • New Topic