在C ++标准库或其他广泛使用的库中的单链表? [英] singly linked list in the C++ standard library or other widely-used libraries?

查看:350
本文介绍了在C ++标准库或其他广泛使用的库中的单链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在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?

推荐答案

slist ,它是一个SGI扩展( __ gnu_cxx :: slist

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

这篇关于在C ++标准库或其他广泛使用的库中的单链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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