为什么没有在STL中进行排序的合并 [英] why no merge without sorting in STL
问题描述
伙计,
我只是好奇为什么标准库没有提供合并。操作
没有排序,因为有时候我不需要排序,只需要合并。
我查看了list.merge()和merge()算法,两者都需要排序
sequenece。
谢谢,
猎人
Folks,
I am just curious why standard library doesn''t provide a "merge" operation
without sorting, because sometimes I don''t require sorting, just merge.
I looked at list.merge() and merge() algorithm, both require sorted
sequenece.
Thanks,
Hunter
推荐答案
Hunter Hou写道:
Hunter Hou wrote:
我很好奇为什么标准库没有提供合并。操作没有排序,因为有时我不需要排序,只需合并。
我查看了list.merge()和merge()算法,两者都需要排序
sequenece。
I am just curious why standard library doesn''t provide a "merge" operation
without sorting, because sometimes I don''t require sorting, just merge.
I looked at list.merge() and merge() algorithm, both require sorted
sequenece.
也许你想要list.splice()?
-
罗素Hanneken
eu*******@cbobk.pbz
使用ROT13解码我的电子邮件地址。
Maybe you want list.splice() ?
--
Russell Hanneken
eu*******@cbobk.pbz
Use ROT13 to decode my email address.
Hunter Hou在新闻中写道:cb ******** @ netnews.proxy.lucent.com in
comp.lang.c ++:
Hunter Hou wrote in news:cb********@netnews.proxy.lucent.com in
comp.lang.c++:
人们,
我很好奇为什么标准库没有提供合并。
操作没有排序,因为有时候我不需要排序,只需要合并。
我查看了list.merge()和merge()算法,两者都需要排序
后续。
Folks,
I am just curious why standard library doesn''t provide a "merge"
operation without sorting, because sometimes I don''t require sorting,
just merge.
I looked at list.merge() and merge() algorithm, both require sorted
sequenece.
这不仅仅是*附加*操作:
#include< iostream>
#include< ostream>
#include< iterator>
#include< vector>
#include<算法>
int main()
{
使用命名空间std;
vector< int> a,b;
a.push_back(1);
b = a;
a.push_back(2);
copy(a.begin(),a.end(),back_inserter(b));
copy(
b .begin(),b.end(),
ostream_iterator< int>(cout," \ n")
);
}
Rob。
-
http://www.victim-prime.dsl.pipex.com/
Rob Williscroft写道:< br>
Rob Williscroft wrote:
这不仅仅是*追加*操作:
#include< iostream>
#include< ostream> ;
#include< iterator>
#include< vector>
#include< algorithm>
int main()
{
使用命名空间std;
vector< int> a,b;
a.push_back(1);
b = a;
a.push_back(2);
复制(a.begin(), a.end(),back_inserter(b));
复制(
b.begin(),b.end(),
ostream_iterator< int>(cout, " \ n")
);
}
Isn''t this just an *append* operation:
#include <iostream>
#include <ostream>
#include <iterator>
#include <vector>
#include <algorithm>
int main()
{
using namespace std;
vector< int > a, b;
a.push_back( 1 );
b = a;
a.push_back( 2 );
copy( a.begin(), a.end(), back_inserter( b ) );
copy(
b.begin(), b.end(),
ostream_iterator< int >( cout, "\n" )
);
}
是的。这是一个解决方案,但不知道它是否像合并一样高效,如果
STL提供。
因为没有排序的合并更多一般来说,这仍然是一个有趣的问题。
问题。
Yes. This is a solution, but don''t know if it''s as efficient as merge if
STL provide .
Since merge without sorting is more general, this is still an intriguing
question.
这篇关于为什么没有在STL中进行排序的合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!