[英]Need help understanding a list container
I am unsure about how this linked list would look like. 我不确定此链表的外观。
list<string> hashTable [HASH_TABLE_SIZE];
I would believe that this one: 我相信这一点:
list<string> hashTable;
would look like this: 看起来像这样:
Head->[]->[]->[]->NULL
but what does 但是是什么
list<string> hashTable [HASH_TABLE_SIZE];
look like? 看起来像?
it would look like this: 它看起来像这样:
[Head][Head][Head]...
^ ^ ^
| | |
v v v
[ ] [ ] [ ]
^ ^ ^
| | |
v v v
NULL NULL NULL
That is an array of std::list's of std::string's, a std::list can be iterated both forwards and backwards, so it is really a doubly linked list. 那是std :: string的std :: list的数组,一个std :: list可以向前和向后迭代,因此它实际上是一个双向链表。 That looks more like the picture below
看起来更像下面的图片
each: 每:
hashTable[index]:
begin()-* *-rbegin()
| |
v v
rend()<-[]<->[]<->[]->end()
/* walk index'th list in hashTable in forward order and print it out */
int f = 0;
list<string>::iterator fwdItr = hashTable[index].begin();
for (; fwdItr != hashTable[index].end(); ++f, ++fwdItr)
{
printf("fwd list entry %d = %s\n", f, *fwdItr);
}
/* walk index'th list in hashTable in reverse order and print it out */
int r = 0;
list<string>::reverse_iterator revItr = hashTable[index].rbegin();
for (; revItr != hashTable[index].rend(); ++r, ++revItr)
{
printf("rev list entry %d = %s\n", r, *revItr);
}
hope this helps illustrate std::list a bit better... 希望这有助于说明std :: list更好一点...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.