Original Post
🔒 Locked
sorting arrays
Advertisement
[font=courier new,courier,monospace]const static int size = 42;[/font]
[font=courier new,courier,monospace]int array[size];[/font]
[font=courier new,courier,monospace]std::sort( array, array+size );[/font]
[edit] An array is just a pointer, and a pointer satisfies the requirements of the "random access iterator" concept, so they can be used with many of the [font=courier new,courier,monospace]std[/font] algorithms.
[font=courier new,courier,monospace]int array[size];[/font]
[font=courier new,courier,monospace]std::sort( array, array+size );[/font]
[edit] An array is just a pointer, and a pointer satisfies the requirements of the "random access iterator" concept, so they can be used with many of the [font=courier new,courier,monospace]std[/font] algorithms.
[font=courier new,courier,monospace]const static int size = 42;[/font]
[font=courier new,courier,monospace]int array[size];[/font]
[font=courier new,courier,monospace]std::sort( array, array+size );[/font]
[edit] An array is just a pointer, and a pointer satisfies the requirements of the "random access iterator" concept, so they can be used with many of the [font=courier new,courier,monospace]std[/font] algorithms.
Might as well link to iterators and random access iterator while you're at it
And while we are at it here are some more search algorithms:
- Insertion
- Merge
- Quick
- Heap
There are more sort methods however and there is a comparison of them here. The selection of your sorts depends on what you want to do, but as stated before std::sort will usually do the job.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement