This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||
|
#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) --
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)
bool compr(stuff a, stuff b) { return a < b; }
--
Spoon!
06:15, 15 October 2007 (UTC)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)
Hi, I am currently considering renaming this article to conform to a common convention for C++ Standard Library components. The full discussion can be found here. decltype 09:47, 6 March 2009 (UTC)
In the paragraph about comparison between C++ sort and C qsort it's said that sort's worst-case complexity is O(N log N). This may be true for the SGI implementation, but other implementations may still have a worst-case complexity of O(N * N). Or is this a general implementation requirement for sort()? At least Bjarne Stroustrup mentions O(N * N) as the limit in "The C++ Programming Language", Special edition.
See also http://www.cplusplus.com/reference/algorithm/sort.html —Preceding unsigned comment added by Ctrlw ( talk • contribs) 17:42, 19 March 2009 (UTC)
This article is rated C-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||||||
|
#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) --
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)
bool compr(stuff a, stuff b) { return a < b; }
--
Spoon!
06:15, 15 October 2007 (UTC)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)
Hi, I am currently considering renaming this article to conform to a common convention for C++ Standard Library components. The full discussion can be found here. decltype 09:47, 6 March 2009 (UTC)
In the paragraph about comparison between C++ sort and C qsort it's said that sort's worst-case complexity is O(N log N). This may be true for the SGI implementation, but other implementations may still have a worst-case complexity of O(N * N). Or is this a general implementation requirement for sort()? At least Bjarne Stroustrup mentions O(N * N) as the limit in "The C++ Programming Language", Special edition.
See also http://www.cplusplus.com/reference/algorithm/sort.html —Preceding unsigned comment added by Ctrlw ( talk • contribs) 17:42, 19 March 2009 (UTC)