帮助双链表 [英] Help with double linked lists

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

问题描述

我在使用双链表时遇到了一些问题,特别是

,这是由Blink和Flink指针决定的。有没有人知道一个好的

网站或一本书,他们会解释如何使用它们?


谢谢

Hi, I''m having some problems when using double linked lists, specially
when it''s up to the Blink an Flink pointers. Does anybody knows a good
site or a book where they explain how to use them?

Thanks

推荐答案

Sigmathaar写道:
Sigmathaar wrote:
我在使用双链表时遇到一些问题,特别是
当它出现时到闪烁一个Flink指针。有没有人知道一个好的网站或一本书,他们解释如何使用它们?
Hi, I''m having some problems when using double linked lists, specially
when it''s up to the Blink an Flink pointers. Does anybody knows a good
site or a book where they explain how to use them?




好​​了,因为这个论坛是标准的C ++语言和库

讨论,我认为你在谈论std :: list的某些特定的b $ b实现。不幸的是,Blink和Flink在这一点上不是标准的一部分,所以我不能对它们发表评论(

至少没有一些代码可以看看),虽然它们可能分别指向后向和前向链接

。您应该查看Josuttis''

_C ++标准库 - 教程和参考_,了解更多关于

如何使用std :: list。或者,拿起任何数据结构书,并且它应该处理它们。


干杯! --M



Well since this forum is for standard C++ language and library
discussions, I presume you''re talking about some particular
implementation of std::list. Unfortunately, Blink and Flink are not
part of the standard on this point, so I can''t comment on them (at
least not without some code to look at), though they probably refer to
the backward and forward links respectively. You should check Josuttis''
_The C++ Standard Library - A Tutorial and Reference_ for more on how
to use std::list. Alternately, pick up any data structures book, and it
should deal with them.

Cheers! --M


是的,Blink和Flink引用了向后和向前的链接,我的问题是

就是它''这是我第一次与他们打交道,而且自从我上次使用C或C ++编写任何内容以来,这也是一个很小的问题。既然没有任何代码可以帮助我很难帮助我,我会给那些给我带来问题的部分。


这是列表的结构:

typedef struct _LIST_ENTRY {

struct _LIST_ENTRY * Flink;

struct _LIST_ENTRY * Blink;

} LIST_ENTRY,* PLIST_ENTRY,* RESTRICTED_POINTER PRLIST_ENTRY;


这些是我正在使用的变量:


静态LIST_ENTRY m_CacheListHead;

LIST_ENTRY * pEntry;

LIST_ENTRY * pEntryNext;

USER_INFO * pUser;


这里是我遇到问题的代码摘录:


for(pEntry = m_CacheListHead.Flink; pEntry !=& m_CacheListHead;

pEntry = pEntryNext)

{

pUser = CONTAINING_RECORD(pEntry,USER_INFO,ListEntry);

pEntryNext = pEntry-> Flink;


pEntry-> Blink-> Flink = pEntry-> Flink;

pEntry-> Flink-> Blink = pEntry-> Blink;


代码用于通过pUser并释放

CacheListHead上的每个条目,但我不明白最后两行

对我来说似乎没用。有人可以解释一下那些

行是什么?

Yes, Blink and Flink refer to the backward and foward links, my problem
is that it''s the first time I''m dealing with them and it''s also been a
littel while since I last coded anything in C or C++. Since it''s
difficult to help me without any code to look I''ll give the part who''s
giving me problems.

This is the struct of the list :

typedef struct _LIST_ENTRY {
struct _LIST_ENTRY *Flink;
struct _LIST_ENTRY *Blink;
} LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;

These are the variables I''m using :

static LIST_ENTRY m_CacheListHead;
LIST_ENTRY* pEntry;
LIST_ENTRY* pEntryNext;
USER_INFO* pUser;

And here''s an extract of the code I''m having problems with :

for ( pEntry = m_CacheListHead.Flink; pEntry != &m_CacheListHead;
pEntry = pEntryNext )
{
pUser = CONTAINING_RECORD( pEntry, USER_INFO, ListEntry );
pEntryNext = pEntry->Flink;

pEntry->Blink->Flink = pEntry->Flink;
pEntry->Flink->Blink = pEntry->Blink;

The code is suposed to go through pUser and free the memory used by
each entry on CacheListHead but I don''t understand the last two lines
which for me seem to be useless. Can somebody explain me what are those
lines for?


* Sigmathaar:
* Sigmathaar:
是的, Blink和Flink是指向后和向前的链接,我的问题是,这是我第一次与他们打交道,而且自从我上次以来它也是一个
littel用C或C ++编写任何代码。因为在没有任何代码的情况下很难帮助我,所以我会给那些给我带来问题的部分。

这是结构清单:

typedef struct _LIST_ENTRY {


以下划线后跟大写字母开头的标识符保留给

实现。


此外,全部大写只应用于宏。


这意味着你正在查看_bad_示例代码。


struct _LIST_ENTRY * Flink;
struct _LIST_ENTRY * Blink;
} LIST_ENTRY,* PLIST_ENTRY,* RESTRICTED_POINTER PRLIST_ENTRY;



这些是我正在使用的变量:

静态LIST_ENTRY m_CacheListHead;
LIST_ENTRY * pEntry;
LIST_ENTRY * pEntryNext;
USER_INFO * pUser;


不要使用全局变量。


这里是我遇到问题的代码的摘录:

for(pEntry = m_CacheListHead.Flink; pEntry!=& m_CacheListHead;
pEntry = pEntryNext)
{
pUser = CONTAINING_RECORD(pEntry,USER_INFO,ListEntry) ;
pEntryNext = pEntry-> Flink;

pEntry-> Blink-> Flink = pEntry-> Flink;
pEntry-> Flink-> Blink = pEntry-> Blink;

代码是通过pUser来释放的,并且释放了CacheListHead上每个条目使用的内存
但我不明白最后一个两条线对我来说似乎毫无用处。有人可以解释一下这些
行是什么吗?
Yes, Blink and Flink refer to the backward and foward links, my problem
is that it''s the first time I''m dealing with them and it''s also been a
littel while since I last coded anything in C or C++. Since it''s
difficult to help me without any code to look I''ll give the part who''s
giving me problems.

This is the struct of the list :

typedef struct _LIST_ENTRY {
Identifier starting with underscore followed by uppercase is reserved to
the implementation.

Also, all uppercase should only be used for macros.

That means you''re looking at _bad_ example code.

struct _LIST_ENTRY *Flink;
struct _LIST_ENTRY *Blink;
} LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;

These are the variables I''m using :

static LIST_ENTRY m_CacheListHead;
LIST_ENTRY* pEntry;
LIST_ENTRY* pEntryNext;
USER_INFO* pUser;
Don''t use global variables.

And here''s an extract of the code I''m having problems with :

for ( pEntry = m_CacheListHead.Flink; pEntry != &m_CacheListHead;
pEntry = pEntryNext )
{
pUser = CONTAINING_RECORD( pEntry, USER_INFO, ListEntry );
pEntryNext = pEntry->Flink;

pEntry->Blink->Flink = pEntry->Flink;
pEntry->Flink->Blink = pEntry->Blink;

The code is suposed to go through pUser and free the memory used by
each entry on CacheListHead
but I don''t understand the last two lines
which for me seem to be useless. Can somebody explain me what are those
lines for?




它们是吞噬内存的好方法。他们取消链接节点并离开

没有指向它的指针。所以它已经丢失了。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



They''re a good way to gobble up memory. They unlink the node and leaves
no pointer to it anywhere. So it''s lost.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


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

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