473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

About list::sort() in STL

Hi there,

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

list<longL

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

Oct 24 '07 #1
14 1557
gj**@mail.utexas.edu wrote:
Hi there,

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

list<longL

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.
Oct 24 '07 #2
On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- 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<longL;

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;
}

Oct 24 '07 #3
gj**@mail.utexas.edu wrote:
#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<longL;

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
Oct 24 '07 #4
"Ek.H" <wa*****@gmail.comwrote in message
news:-9*********************@telenor.com...
gj**@mail.utexas.edu wrote:
>#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<longL;

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
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.
Oct 24 '07 #5
gj**@mail.utexas.edu wrote:
On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
>g...@mail.utexas.edu wrote:
>>Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- Hide quoted text -

- Show quoted text -


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?
#include <iostream>
#includer<list>

using namespace std;

int main()
{

list<longL;

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;
}
Oct 24 '07 #6
On 2007-10-24 20:11, gj**@mail.utexas.edu wrote:
On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
>g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- 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<longL;

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.

--
Erik Wikström
Oct 24 '07 #7
On Oct 24, 1:40 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
"Ek.H" <wand...@gmail.comwrote in message

news:-9*********************@telenor.com...


g...@mail.utexas.edu wrote:
#include <iostream>
#includer<list>
using namespace std;
int main()
{
list<longL;
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

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
Oct 24 '07 #8
gj**@mail.utexas.edu wrote:
On Oct 24, 1:40 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>>g...@mail.utexas.edu wrote:
#include <iostream>
#includer<list>
using namespace std;
int main()
{
list<longL;
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;
}
>
First, If I sorted a smaller list (5000 elements), it works well.
See my comment. 479250 % 65536 is 20498. It sounds like a truncation
error.
Oct 24 '07 #9
On Oct 24, 1:51 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-24 20:11, g...@mail.utexas.edu wrote:


On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- 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<longL;
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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -
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

Oct 24 '07 #10
On 2007-10-24 21:11, gj**@mail.utexas.edu wrote:
On Oct 24, 1:51 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-10-24 20:11, g...@mail.utexas.edu wrote:


On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- 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<longL;
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.

--
Erik Wikström- Hide quoted text -
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.

--
Erik Wikström
Oct 24 '07 #11
On Oct 24, 2:57 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-24 21:11, g...@mail.utexas.edu wrote:


On Oct 24, 1:51 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-24 20:11, g...@mail.utexas.edu wrote:
On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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 exhibitsthe
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<longL;
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.
--
Erik Wikström- Hide quoted text -

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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -
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
Oct 24 '07 #12
On Wed, 24 Oct 2007 11:11:20 -0700, gj**@mail.utexas.edu wrote:
>On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
I use Visual C++ 6.0. Here is a simple example I test, which does not
work.
http://www.dinkumware.com/vc_fixes.html

--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Oct 24 '07 #13
plx
yeah ,i paste compile the code in vc2005,it has same output.but it takes
about 1 minute.
<gj**@mail.utexas.edu>
??????:11**********************@q5g2000prf.googleg roups.com...
On Oct 24, 1:51 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-24 20:11, g...@mail.utexas.edu wrote:


On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:
g...@mail.utexas.edu wrote:
Hi there,
I met a problem, which I could not solve. I used it as the
following:
list<longL
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.- 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<longL;
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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -
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

Oct 25 '07 #14
Not"479250%65536 is 20498",that is "479250%32768 is 20498".
I met the same problem,too.That size of list is aboat 40000.

Oct 26 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Amy G | last post by:
I have a list of numbers... actully I have two lists, List 1 is a list of number strings and List2 is one of numbers. List 1 example: List1 = List 2 example: List2 = When I try either:
2
by: Wiseguy | last post by:
OK. I need to sort a list and I have the following code @L=(35,10,0,27,100,-4); sub numeric { $A <=> $b; } @L=sort numeric @L; The only reference I have is an ancient Oreilly book on Perl 4....
3
by: Math Preregistration System | last post by:
I'm using a std::list as a container for some pointers to objects, for example list< C* > lst; I would like to sort them using two different criteria, say first by C.first and then by...
2
by: Tim Partridge | last post by:
How do I define the use of list::sort() when the list holds pointers? For example, #include <list> class foo { public: foo(int i): i(i) {}; ~foo();
99
by: Shi Mu | last post by:
Got confused by the following code: >>> a >>> b >>> c {1: , ], 2: ]} >>> c.append(b.sort()) >>> c {1: , ], 2: , None]}
11
by: ankyhe | last post by:
L = L=L.sort() L will refer to None, why L.sort() don't return the L? I want to ask why the designer of Python do so?
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
3
by: jason.cipriani | last post by:
How can I use my own custom comparison function with std::list::sort()? The only call to sort() I see does not take a predicate argument. Specifically, I have: list<pair<double,MyType ...; ...
1
by: Steven Clark | last post by:
If I have a list of items of mixed type, can I put something into it such that after a list.sort(), is guaranteed to be at the end of the list? Looking at...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.