C++ 中的单链表标准库或其他广泛使用的库?

发布于 2024-09-01 02:06:38 字数 52 浏览 3 评论 0原文

好像C++标准库里只有双向链表(没有单链表)吧?是否有广泛使用的带有单链表的 C++ 库?

Seems that there is only doubly linked list (but no singly linked list) in the C++ standard library, right? Is there any widely-used C++ libraries with singly linked list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

归属感 2024-09-08 02:06:38

There is the slist class from Boost that is a singly linked list implementation.

べ映画 2024-09-08 02:06:38

仅供参考...

时间已经过去,C++11 为我们带来了 std:: forward_list 容器实现为单链表,与 C 中的实现相比,本质上没有任何开销。

std::list 相比,此容器在以下情况下提供更节省空间的存储:不需要双向迭代。

警告:缺少 push_back 方法(std::forward_list 和 std: :forward_list::push_back)

Just for reference...

Time has passed and C++11 has brought us the std::forward_list container that is implemented as a singly-linked list and essentially does not have any overhead compared to its implementation in C.

Compared to std::list this container provides more space efficient storage when bidirectional iteration is not needed.

Warning: missing push_back method (std::forward_list and std::forward_list::push_back)

甜味超标? 2024-09-08 02:06:38

slist,它是一个 SGI 扩展(__gnu_cxx::清单)

#include <iostream>
#include <iterator>
#include <ext/slist>

int main(int argc, char** argv) {
  __gnu_cxx::slist<int> sl;
  sl.push_front(1);
  sl.push_front(2);
  sl.push_front(0);
  std::copy(sl.begin(), sl.end(),  // The output is 0 2 1
            std::ostream_iterator<int>(std::cout, " "));
  std::cout << std::endl;
  return 0;
}

There is slist, which is an SGI extension (__gnu_cxx::slist)

#include <iostream>
#include <iterator>
#include <ext/slist>

int main(int argc, char** argv) {
  __gnu_cxx::slist<int> sl;
  sl.push_front(1);
  sl.push_front(2);
  sl.push_front(0);
  std::copy(sl.begin(), sl.end(),  // The output is 0 2 1
            std::ostream_iterator<int>(std::cout, " "));
  std::cout << std::endl;
  return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文