我只需要通過名稱有順序的鏈接列表。我只能得到第一,第三,第五,...節點。我想不出這麼遠。我想成爲一名C++程序員,但如果我不明白這是他們的任何希望?作爲學生,STL容器std::lists
在這一點上不適合我。你在列表中看到的是我想要理解的東西。
list::node::node(const winery &winery) : item(winery.getName(), winery.getLocation(),
winery.getAcres(), winery.getRating()), nextByName(NULL), nextByRating(NULL)
{
}
void list::insert(const winery& winery)
{
node *current_node = new node(winery); // but came here and did this so it has new info!
node *next_node = NULL;
node *tail_node = current_node;
if (headByName == NULL) // then we are here for the first item
{
headByName = current_node; // the list ptrs will have the first node's address.
headByRating = current_node;
}
while (headByName->nextByName != NULL)
{
headByName->nextByName = tail_node;
tail_node = next_node;
//next_node = current_node;
}
tail_node = new node(winery);
headByName->nextByName = tail_node;
}
而這是提供給我的指點:
struct node
{
winery item;
node * nextByName;
node * nextByRating;
};
class list
{
...
private:
node * headByName;
node * headByRating;
};
看起來像一個單鏈表對我來說,不是一個雙向鏈表... – 2009-08-24 04:21:08
這不是傳統意義上的雙向鏈表,但它*是一個列表,表示同一組節點的兩種不同順序。通常的順序是通過插入順序和反向插入順序,但在這種情況下(根據變量名稱),它們是按名稱進行評分的。 – 2009-08-24 04:27:04
燈罩,不要以這種方式編輯您的文章。 – GManNickG 2009-09-12 22:23:53