草庐IT

external-sorting

全部标签

c++ - 为什么 std::sort 不通过引用接受比较器?

standardonstd::reference_wrapper解释说std::sort现在接受std::reference_wrapper,允许通过引用传递比较器。std::sort一开始没有通过引用接受比较器是否有原因? 最佳答案 简而言之,没有必要引用它;这相当于一个“设计”的决定。我相信推理集中在C++和标准库中已经存在很长时间的一些基本原理上;值语义对实现施加尽可能少的限制值语义几乎随处可见。几乎所有的算法、容器等都期望其中包含的数据遵守正常的值规则,即表现得好像它们是内置类型一样。这也是C++类型系统背后的原因之一,它使

c++ - 流行的 C++ 编译器对 std::sort 和 std::stable_sort 使用什么算法?

流行的C++编译器对std::sort和std::stable_sort使用什么算法?我知道标准只给出了某些性能要求,但我想知道流行的实现在实践中使用了哪些算法。如果它引用每个实现的引用,答案会更有用。 最佳答案 首先:编译器不提供std::sort的任何实现。虽然传统上每个编译器都预先打包了一个标准库实现(它严重依赖于编译器的内置),但理论上您可以将一个实现换成另一个。一个很好的例子是Clang编译libstdc++(传统上使用gcc打包)和libc++(全新)。现在已经不碍事了……std::sort传统上被实现为intro-so

c++ - 流行的 C++ 编译器对 std::sort 和 std::stable_sort 使用什么算法?

流行的C++编译器对std::sort和std::stable_sort使用什么算法?我知道标准只给出了某些性能要求,但我想知道流行的实现在实践中使用了哪些算法。如果它引用每个实现的引用,答案会更有用。 最佳答案 首先:编译器不提供std::sort的任何实现。虽然传统上每个编译器都预先打包了一个标准库实现(它严重依赖于编译器的内置),但理论上您可以将一个实现换成另一个。一个很好的例子是Clang编译libstdc++(传统上使用gcc打包)和libc++(全新)。现在已经不碍事了……std::sort传统上被实现为intro-so

c++ - 是否有任何理由在没有方法的 header 上使用 extern "C"?

我经常遇到包含extern"C"保护的C头文件,但不包含任何实际功能。例如:/*b_ptrdiff.h-basetypeptrdiff_tdefinitionheader*/#ifndef__INCb_ptrdiff_th#define__INCb_ptrdiff_th#ifdef__cplusplusextern"C"{#endif#ifndef_PTRDIFF_T#define_PTRDIFF_Ttypedeflongptrdiff_t;#endif/*_PTRDIFF_T*/#ifdef__cplusplus}#endif#endif/*__INCb_ptrdiff_th*/我知

c++ - 是否有任何理由在没有方法的 header 上使用 extern "C"?

我经常遇到包含extern"C"保护的C头文件,但不包含任何实际功能。例如:/*b_ptrdiff.h-basetypeptrdiff_tdefinitionheader*/#ifndef__INCb_ptrdiff_th#define__INCb_ptrdiff_th#ifdef__cplusplusextern"C"{#endif#ifndef_PTRDIFF_T#define_PTRDIFF_Ttypedeflongptrdiff_t;#endif/*_PTRDIFF_T*/#ifdef__cplusplus}#endif#endif/*__INCb_ptrdiff_th*/我知

C++ STL : Custom sorting one vector based on contents of another

这个问题在这里已经有了答案:HowdoIsortastd::vectorbythevaluesofadifferentstd::vector?[duplicate](13个回答)关闭8年前。这可能是最好的例子。我有两个vector/列表:People={Anne,Bob,Charlie,Douglas}Ages={23,28,25,21}我想使用sort(People.begin(),People.end(),CustomComparator)之类的方法根据年龄对People进行排序,但我不知道如何编写CustomComparator查看年龄而不是人物。 最

C++ STL : Custom sorting one vector based on contents of another

这个问题在这里已经有了答案:HowdoIsortastd::vectorbythevaluesofadifferentstd::vector?[duplicate](13个回答)关闭8年前。这可能是最好的例子。我有两个vector/列表:People={Anne,Bob,Charlie,Douglas}Ages={23,28,25,21}我想使用sort(People.begin(),People.end(),CustomComparator)之类的方法根据年龄对People进行排序,但我不知道如何编写CustomComparator查看年龄而不是人物。 最

c++ - std::nth_element 和 std::sort 之间的实际区别是什么?

我一直在研究std::nth_element算法,显然:Rearrangestheelementsintherange[first,last),insuchawaythattheelementattheresultingnthpositionistheelementthatwouldbeinthatpositioninasortedsequence,withnoneoftheelementsprecedingitbeinggreaterandnoneoftheelementsfollowingitsmallerthanit.Neithertheelementsprecedingitno

c++ - std::nth_element 和 std::sort 之间的实际区别是什么?

我一直在研究std::nth_element算法,显然:Rearrangestheelementsintherange[first,last),insuchawaythattheelementattheresultingnthpositionistheelementthatwouldbeinthatpositioninasortedsequence,withnoneoftheelementsprecedingitbeinggreaterandnoneoftheelementsfollowingitsmallerthanit.Neithertheelementsprecedingitno

C++ vector 问题 - 'LNK2001: unresolved external symbol private: static...'

在有人指责我不查看预先存在的问题之前,我已经查看并意识到它与声明有关,但我仍然无法让它工作(可能与我使用vector有关)。Manager.h:#include"Flight.h"#ifndefmanager_h#definemanager_hclassManager{staticvectorairports;staticvectorflights;public:staticvoidloadAirports();staticvoidloadFlights();staticAirportgetAirport(stringcode);staticvectorsplit(conststrin