C / C ++中的链接列表 [英] Linked lists in C/C++

查看:81
本文介绍了C / C ++中的链接列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我只是对C ++有一个简单的问题。我正在从Java转向C ++。而且,许多Java用户都知道,所有链表和树都已实现

,你只需要实例化它们即可。在c ++中tehre是一个类似的东西,或者我/ b $ b必须编写我自己的Linked list类吗?


非常感谢

干杯

Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?

Thank you very much
Cheers

推荐答案

hana1写道:
大家好,我刚才有一个关于C ++的快速问题。我正在从Java转向C ++。正如许多Java用户所知,所有链表和树都已经实现了,你只需要实例化它们即可。在c ++中tehre是一个类似的东西,还是我必须编写自己的Linked list类?

非常感谢
干杯
Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?

Thank you very much
Cheers




标准库有许多容器,包括矢量,deques,

列表,集合和映射。我不确定是否有股票树。 class

(虽然集合和地图往往被实现为红/黑树)。


获取Josuttis'''C ++标准版的副本图书馆" ;.另外,获得

Koenig& Moo'的Accelerated C ++。



The Standard Library has many containers, including vectors, deques,
lists, sets, and maps. I''m not sure if there''s a stock "tree" class
(though sets and maps tend to be implemented as a red/black tree).

Get a copy of Josuttis'' "The C++ Standard Library". Also, get
Koenig&Moo''s "Accelerated C++".


hana1写道:
大家好,我刚才有一个关于C ++的快速问题。我正在从Java转向C ++。正如许多Java用户所知,所有链表和树都已经实现了,你只需要实例化它们即可。在c ++中tehre是一个类似的东西,还是我必须编写自己的Linked list类?
Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?




只是为了添加Red的注释,那里有很多网站都有

文件。


即使它有点过时,我仍然认为它是最有用的/>
在线参考:
http:// www.sgi.com/tech/stl/


还有很多其他的:
http://www.codeproject.com/vcpp/stl/stlintroduction.asp


许多在线示例都有一个.h。在包含文件中。这些都是错的。



Just to add to Red''s note, there are a number of web sites that have
documentation.

Even though it''s a little out of date, I still find it the most useful
on-line reference:
http://www.sgi.com/tech/stl/

There are plenty of others :
http://www.codeproject.com/vcpp/stl/stlintroduction.asp

Many on-line examples have a ".h" in the include file. These are wrong.


>我刚才有一个关于C ++的快速问题。我正在从Java转向C ++。并且正如
> I just have a quick question about C++. I am moving from Java to C++. And as
许多Java用户都知道的那样,所有链表和树都已经实现了,你只需要实例化它们。在c ++中tehre是一个类似的东西,还是我必须编写自己的Linked list类?
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?




在C ++中,STL定义列表(双向链接) list)和slist(一个

单链表)。请参见:

http:// www .sgi.com / tech / stl / List.html
http://www.sgi.com/tech/stl/Slist.html


但有一件事是,C / C ++只支持同质列表 - 即

每个列表中只有一种数据类型,除非你存储指针而是

的值。


但是,如果你自己编写,你可以做更高级的东西,

喜欢共享列表节点和其他有趣的东西。请参阅我关于链接的文章

列表:

http://www.ibm.com/developerworks/li...ry/l-listproc/


另外来自Java,如果你决定错过垃圾收集,

你可以随时使用Boehm垃圾收集器将其添加回来。

http://www.hpl.hp.com/personal/Hans_Boehm/gc/


Jon

----

学习使用Linux汇编语言编程
http://www.cafeshops.com/bartlettpublish.8640017



In C++ the STL defines list (a doubly-linked list) and slist (a
singly-linked list). See here:

http://www.sgi.com/tech/stl/List.html
http://www.sgi.com/tech/stl/Slist.html

One thing, though, is that C/C++ only support homogenous lists -- i.e.
only one data type in each list, unless you are storing pointers instead
of values.

However, you can do more advanced type of stuff if you write your own,
like sharing list nodes and other fun stuff. See my article on linked
lists here:

http://www.ibm.com/developerworks/li...ry/l-listproc/

Also, coming from Java, if you decide that you miss garbage collection,
you can always add it back using the Boehm garbage collector.

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017


这篇关于C / C ++中的链接列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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