gpt4 book ai didi

c++ - DoublyLinkedList 删除错误

转载 作者:太空狗 更新时间:2023-10-29 20:15:41 24 4
gpt4 key购买 nike

我正在制作一个双向链表。错误与我的 Remove 方法有关。我想不通。有谁知道吗?

这里是哪里出错了?

Error 1 error C2027: use of undefined type 'DoublyListNode' c:\users\conor\documents\college\c++\projects\repeat - doublylinkedlist\repeat - doublylinkedlist\doublylinkedlist.h 230 1 Repeat - DoublyLinkedList

// -------------------------------------------------------------------------------------------------------
// Name: Remove
// Description: Removes the node that the iterator points to, moves iterator forward to the next node.
// Arguments: p_iterator: The iterator to remove
// isForward: Tells which direction the iterator was going through the list
// Return Value: None.
// -------------------------------------------------------------------------------------------------------
void Remove(DoublyListIterator<Datatype>& m_itr)
{
DoublyListNode<Datatype>* node = m_head;
// if the iteratordoesn’t belong to this list, do nothing.
if (m_itr.m_list != this)
return;
// if node is invalid, do nothing.
if (m_itr.m_node == 0)
return;
if (m_itr.m_node == m_head)
{
// move the iteratorforward and delete the head.
m_itr.Forth();
RemoveHead();
m_size--;
}
else
{
// scan forward through the list until you find
// the node prior to the node you want to remove
while (node->m_next != m_itr.m_node)
node = node->m_next;
// move the iterator forward.
m_itr.Forth();
// if the node you are deleting is the tail,
// update the tail node.
if (node->m_next == m_tail)
{
m_tail = node;
}
// delete the node.
delete node->m_next;
// re-link the list.
node->m_next = m_itr.m_node;
m_size--;
}
}

如果需要更多代码,请询问。我不想在 Stack overflow 用户上放置大量代码。

最佳答案

问题是类 DoublyListNode 的拼写错误。该类名为 DLNode。所以这导致了上面讨论的错误。

关于c++ - DoublyLinkedList 删除错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12124958/

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