C ++中是否有链接列表预定义库?

时间:2021-07-30 07:21:51

Is there a linked list in C++ that I could just #include? Or do I need to create my own if I want to use one?

C ++中是否有链接列表,我可以#include?或者,如果我想使用它,我是否需要创建自己的?

5 个解决方案

#1


35  

As daniel notes, yes, std::list. Usage would be:

正如daniel所说,是的,std :: list。用法是:

#include <list>
// ...
std::list<int> listOfInts;
listOfInts.push_back(1);
// ...

And so on.

等等。

You can find a complete list of STL classes here. The section you're after is 3.2, Container classes. Another useful reference of the C++ Standard Library is here.

您可以在此处找到完整的STL课程列表。您所追求的部分是3.2,容器类。这里是C ++标准库的另一个有用的参考。

#2


9  

#include <list>

#3


4  

In c++ we have the STL, Standard Template Libraries which do contain a a lot of implemantations of popular data structures and algorithms like stacks, queues, linked lists and popular searching and sorting algorithms even.....

在c ++中,我们有STL标准模板库,它们包含大量流行数据结构和算法的实现,如堆栈,队列,链表和流行的搜索和排序算法甚至......

As already told by daniel you can include it by #include< list>

正如daniel所说,你可以通过#include 包含它

#4


3  

STL List

#5


2  

If you are open to looking into Qt, you might want to try out their containers (like QList, QMap, and the very cool QString). QList supports the C++ iterator pattern, as well as the arguably easier "Java-style iterators"...which look more like this:

如果您愿意查看Qt,您可能想要尝试他们的容器(如QList,QMap和非常酷的QString)。 QList支持C ++迭代器模式,以及可以说更容易的“Java风格迭代器”......看起来更像是这样:

QList<QString> list;
list << "A" << "B" << "C" << "D";

QListIterator<QString> i(list);
while (i.hasNext())
    qDebug() << i.next();

The idea that C++ programmers should always use the standard library should be taken with a grain of salt. For lists, maps, strings, and almost everything else...you will find that high-profile projects often use something else. The source code to Mozilla has 9 of its own different concrete classes for strings, because std::string just didn't meet their needs for internationalization/etc.

C ++程序员应该始终使用标准库的想法应该采取一些措施。对于列表,地图,字符串以及几乎所有其他内容......您会发现高调项目经常使用其他内容。 Mozilla的源代码有9个不同的字符串具体类,因为std :: string只是不能满足国际化/等的需要。

While you shouldn't always use the C++ standard library in every kind of project, you should definitely know HOW to use it. It contains classes that are extremely general, well-tested, well-documented, and available on every installation. This makes it a good baseline for communicating with other C++ programmers about algorithms / etc.

虽然你不应该总是在各种项目中使用C ++标准库,但你应该知道如何使用它。它包含非常通用,经过良好测试,文档齐全且每次安装都可用的类。这使它成为与其他C ++程序员就算法/等进行通信的良好基线。

#1


35  

As daniel notes, yes, std::list. Usage would be:

正如daniel所说,是的,std :: list。用法是:

#include <list>
// ...
std::list<int> listOfInts;
listOfInts.push_back(1);
// ...

And so on.

等等。

You can find a complete list of STL classes here. The section you're after is 3.2, Container classes. Another useful reference of the C++ Standard Library is here.

您可以在此处找到完整的STL课程列表。您所追求的部分是3.2,容器类。这里是C ++标准库的另一个有用的参考。

#2


9  

#include <list>

#3


4  

In c++ we have the STL, Standard Template Libraries which do contain a a lot of implemantations of popular data structures and algorithms like stacks, queues, linked lists and popular searching and sorting algorithms even.....

在c ++中,我们有STL标准模板库,它们包含大量流行数据结构和算法的实现,如堆栈,队列,链表和流行的搜索和排序算法甚至......

As already told by daniel you can include it by #include< list>

正如daniel所说,你可以通过#include 包含它

#4


3  

STL List

#5


2  

If you are open to looking into Qt, you might want to try out their containers (like QList, QMap, and the very cool QString). QList supports the C++ iterator pattern, as well as the arguably easier "Java-style iterators"...which look more like this:

如果您愿意查看Qt,您可能想要尝试他们的容器(如QList,QMap和非常酷的QString)。 QList支持C ++迭代器模式,以及可以说更容易的“Java风格迭代器”......看起来更像是这样:

QList<QString> list;
list << "A" << "B" << "C" << "D";

QListIterator<QString> i(list);
while (i.hasNext())
    qDebug() << i.next();

The idea that C++ programmers should always use the standard library should be taken with a grain of salt. For lists, maps, strings, and almost everything else...you will find that high-profile projects often use something else. The source code to Mozilla has 9 of its own different concrete classes for strings, because std::string just didn't meet their needs for internationalization/etc.

C ++程序员应该始终使用标准库的想法应该采取一些措施。对于列表,地图,字符串以及几乎所有其他内容......您会发现高调项目经常使用其他内容。 Mozilla的源代码有9个不同的字符串具体类,因为std :: string只是不能满足国际化/等的需要。

While you shouldn't always use the C++ standard library in every kind of project, you should definitely know HOW to use it. It contains classes that are extremely general, well-tested, well-documented, and available on every installation. This makes it a good baseline for communicating with other C++ programmers about algorithms / etc.

虽然你不应该总是在各种项目中使用C ++标准库,但你应该知道如何使用它。它包含非常通用,经过良好测试,文档齐全且每次安装都可用的类。这使它成为与其他C ++程序员就算法/等进行通信的良好基线。