gpt4 book ai didi

c++ - 为什么STL不提供c风格列表?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:19:29 25 4
gpt4 key购买 nike

我想要的东西可以提供:

std::list head;
std::list::node node;
while (node = head->next) {
do something with this node
};

列表没有下一个指针对我来说很奇怪。

最佳答案

因为 C++11 STL 有一个单链表。它的使用类似于普通的双向链表。

特别是:

std::forward_list<node> my_list;

for(auto iter = my_list.begin(); iter != my_list.end(); ++iter)
{
node &curr_node = *iter;
// Do something with curr_node.
}

关于c++ - 为什么STL不提供c风格列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com