|
-
February 20th, 2008, 07:00 AM
#1
Problem With STL List Sort
Hello,
I am having a problem sorting a large list. Below is an example.
Code:
#include <iostream>
#include <list>
using namespace std;
void main()
{
list<int> ints;
for(int k=0;k<50000;k++) ints.push_back(k);
ints.sort();
cout << "ints.size(): " << ints.size() << endl;
}
The number of integers left in ints is 17232, meaning some were lost during ints.sort(). I would like to know what the cause of the problem is and the sorting algorithm used in sort(). Thank you for this information or a link to it.
dremmuel
-
February 20th, 2008, 10:55 AM
#2
Re: Problem With STL List Sort
Works fine in Visual Studio 2005.
-
February 20th, 2008, 11:32 AM
#3
Re: Problem With STL List Sort
Maybe it's just an issue with Visual Studio 6.0. I was able to sort the list by sorting parts of it and merging the parts together. I suppose it will have to do until I can get my hands on Visual Studio 2005.
Thanks for the information John.
-
February 20th, 2008, 12:20 PM
#4
Re: Problem With STL List Sort
I just tried it in Visual Studio 6.0 and got the same results as you.
The maximum number of elements it can sort seems to be 32767, which is the maximum positive value of a 16bit signed integer.
It appears to roll-over its count after 32767
50000 - 32768 = 17232
Last edited by JohnW@Wessex; February 20th, 2008 at 12:28 PM.
-
February 20th, 2008, 05:12 PM
#5
Re: Problem With STL List Sort
See "FIX: Listing Sort Function Removes Elements" at http://support.microsoft.com/kb/240014
It's an "off by one" coding error. Fixed in Visual C++ .NET.
Scary, isn't it?
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|