关于STL中的list :: sort() [英] About list::sort() in STL

查看:86
本文介绍了关于STL中的list :: sort()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我遇到了一个问题,我无法解决。我用它作为

跟随:


list< longL


for(long i = 1; i< ; = 479250; i ++)

L.push_back(i);


L.size(); //这给了479250;


L.sort();


L.size(); //这里给出20498?


为什么列表中的元素被删除?我无法理解


真的很感谢你的帮助!


ucb

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

推荐答案

gj**@mail.utexas.edu 写道:

你好,


我遇到了一个问题,我无法解决。我用它作为

跟随:


list< longL


for(long i = 1; i< ; = 479250; i ++)

L.push_back(i);


L.size(); //这给了479250;


L.sort();


L.size(); //这里给出20498?


为什么列表中的元素被删除?我无法理解


真的很感谢你的帮助!
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!



在g ++ 3.4.4中不会发生。你的平台是什么?请提供

最小*可编辑*(强调可编译)示例,展示有问题的

行为。


谢谢。

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.


10月24日下午12:35,red floyd< no.s ... @ here.dudewrote:
On Oct 24, 12:35 pm, red floyd <no.s...@here.dudewrote:

g ... @ mail.utexas.edu写道:
g...@mail.utexas.edu wrote:

你好,
Hi there,


我遇到了一个问题,我无法解决。我用它作为

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


list< longL
list<longL


for(long i = 1; i< = 479250; i ++)

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


L.size(); //这给出了479250;
L.size(); // this gives 479250;


L.sort();
L.sort();


L.size(); //这里给出20498?
L.size(); // Here it gives 20498?


为什么列表中的元素被删除?我无法理解它
Why the elements in the list are removed??? I could not understand it


真的很感谢你的帮助!
Really appreciate your help!



在g ++ 3.4.4中不会发生。你的平台是什么?请提供

最小*可编辑*(强调可编译)示例,展示有问题的

行为。


谢谢.-隐藏引用文本 -


- 显示引用文本 -


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 -



我使用Visual C ++ 6.0。这是一个我测试的简单例子,它没有工作。


#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; //给479250

L.sort();


cout<< L.size()<< ENDL; //给20498; ???


返回0;

}


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


gj**@mail.utexas.edu 写道:
gj**@mail.utexas.edu wrote:

#include< iostream>

#includer< list>


使用命名空间std;


int main( )

{


list< longL;


for(long i = 1; i< = 479250; i ++)

L.push_back(i);


cout<< L.size()<< ENDL; //给479250

L.sort();


cout<< L.size()<< ENDL; //给20498; ???


返回0;

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



之后我使用gcc版本4.1.2将#includer更改为#include它正常工作

。可能

是使用Visual C ++ 6.0的一两个bug。


~

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.

~


这篇关于关于STL中的list :: sort()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆