Talk:Sort (C++)

From Wikipedia, the free encyclopedia

This article is supported by the Wikipedia:WikiProject C++. Please visit the project page for more details on the project.
  1. include <iostream>
#include <algorithm>

int main() {
  int array[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30 };
  int elements = sizeof(array) / sizeof(int); 
  std::sort(a, a + elements);
  for (int i = 0; i < elements; ++i) std::cout << array[i] << ' ';
  return 0;
}

a is not defined here. What is it supposed to be? --Abdull 12:21, 23 June 2006 (UTC)

-- Looks like it should be "array"... I'm fixing it. Dlong 04:42, 28 July 2006 (UTC) --

Example needed

I'm a newb cpp prog (taking a course in college). The optional third argument function compare has no example given. I believe it's supposed to go like this:


bool compr(stuff a, ...., etc b) {

   //stuff 

}

....
sort(a.begin(),a.end(),compr);


Can someone who knows what the real way to do it is put the example in? --128.113.193.67 09:45, 15 September 2006 (UTC)

Something like this, depending on your data type: bool compr(stuff a, stuff b) { return a < b; } --Spoon! 06:15, 15 October 2007 (UTC)

[edit] Referneces

Does anyone have the references for the speed of implementation, including practical examples. We could generate them by ourselves, but that would be WP:OR.... 121.44.5.248 (talk) 13:43, 1 June 2008 (UTC)