About list::sort() in STL

G

gjin

Hi there,

I met a problem, which I could not solve. I used it as the
following:

list<long> L

for (long i=1;i<=479250; i++)
L.push_back(i);

L.size(); // this gives 479250;

L.sort();

L.size(); // Here it gives 20498?

Why the elements in the list are removed??? I could not understand it

Really appreciate your help!

ucb
 
R

red floyd

Hi there,

I met a problem, which I could not solve. I used it as the
following:

list<long> L

for (long i=1;i<=479250; i++)
L.push_back(i);

L.size(); // this gives 479250;

L.sort();

L.size(); // Here it gives 20498?

Why the elements in the list are removed??? I could not understand it

Really appreciate your help!

Doesn't happen in g++ 3.4.4. What is your platform? Please provide a
minimal *COMPILABLE* (emphasis on compilable) example that exhibits the
behavior in question.

Thank you.
 
G

gjin

Doesn't happen in g++ 3.4.4. What is your platform? Please provide a
minimal *COMPILABLE* (emphasis on compilable) example that exhibits the
behavior in question.

Thank you.- Hide quoted text -

- Show quoted text -


I use Visual C++ 6.0. Here is a simple example I test, which does not
work.

#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<long> L;

for (long i=1;i<=479250; i++)
L.push_back(i);

cout<< L.size()<<endl; // give 479250

L.sort();

cout<< L.size() << endl; // give 20498;???

return 0;
}
 
E

Ek.H

#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<long> L;

for (long i=1;i<=479250; i++)
L.push_back(i);

cout<< L.size()<<endl; // give 479250

L.sort();

cout<< L.size() << endl; // give 20498;???

return 0;
}

After I changed the #includer to #include it worked
correctly for me using gcc version 4.1.2. There might
be a bug or two with Visual C++ 6.0.

~ $ ./a.out
479250
479250
 
J

Jim Langston

Ek.H said:
After I changed the #includer to #include it worked
correctly for me using gcc version 4.1.2. There might
be a bug or two with Visual C++ 6.0.

~ $ ./a.out
479250
479250

A bug or 2? A few hundred is more like it. I would suggest you go download
Microsoft C++ 2005 Express (Free). 6.0 not only has a lot of bugs, but it
was pre-standard.
 
R

red floyd

I use Visual C++ 6.0. Here is a simple example I test, which does not
work.

VC6 is known for buggy implementations of templates. This looks to be
an error in the compiler or library (Sorry PJ and Pete!). That is,
assuming that you ran the code below (after fixing the typo) and got the
output you claimed.

The other issue is that it could be a data type error. Note that
479250%65536 is 20498.

Are you sure that's the actual code you tested, and that you're not
assigning to any variables in between?
 
G

Guest

I use Visual C++ 6.0. Here is a simple example I test, which does not
work.

#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<long> L;

for (long i=1;i<=479250; i++)
L.push_back(i);

cout<< L.size()<<endl; // give 479250

L.sort();

cout<< L.size() << endl; // give 20498;???

return 0;
}

Not reproducible in VC++ 2005, seems like an implementation bug to me.
 
G

gjin

A bug or 2? A few hundred is more like it. I would suggest you go download
Microsoft C++ 2005 Express (Free). 6.0 not only has a lot of bugs, but it
was pre-standard.- Hide quoted text -

- Show quoted text -

Thanks for your reply.

First, If I sorted a smaller list (5000 elements), it works well.

Second, Is STL included in the Visual C++ 6.0?

ucb
 
G

gjin

Not reproducible in VC++ 2005, seems like an implementation bug to me.

About red floyd reply:

Yes, I used the above code to test exactly on my computer. I got wrong
result.

I guess it was caused by my visual C++ 6.00 or Standard Template
Library

Does anyone use visual C++ 6.00 and can help test it?

About Erik's reply:

Does you mean that my test code works well in your Visual C++ 2005?

Thanks, ucb
 
G

Guest

Please do not quote signatures.
About red floyd reply:

Yes, I used the above code to test exactly on my computer. I got wrong
result.

I guess it was caused by my visual C++ 6.00 or Standard Template
Library

Does anyone use visual C++ 6.00 and can help test it?

About Erik's reply:

Does you mean that my test code works well in your Visual C++ 2005?

Yes, it works just fine for me.
 
G

gjin

Please do not quote signatures.







Yes, it works just fine for me.

Thanks. I got the answer. It was caused by the bugs
in Visual C++ 6.00. I will update my compiler.
Really appreicate your helps!

ucb
 
P

plx

yeah ,i paste compile the code in vc2005,it has same output.but it takes
about 1 minute.


<[email protected]>
??????:[email protected]...
Not reproducible in VC++ 2005, seems like an implementation bug to me.

About red floyd reply:

Yes, I used the above code to test exactly on my computer. I got wrong
result.

I guess it was caused by my visual C++ 6.00 or Standard Template
Library

Does anyone use visual C++ 6.00 and can help test it?

About Erik's reply:

Does you mean that my test code works well in your Visual C++ 2005?

Thanks, ucb
 
G

guospring

Not"479250%65536 is 20498",that is "479250%32768 is 20498".
I met the same problem,too.That size of list is aboat 40000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,642
Latest member
arunkumar99

Latest Threads

Top