C++ 链表与特殊类、函数和指针详解
链表的实现与操作
链表是一种动态大小的集合,每个数据对象都存储在链表的节点中。要访问特定的节点,必须从链表的一端开始遍历,直到找到所需的节点。
以下是链表相关的代码实现:
private:
Node * myNext;
};
// As soon as the head is created
// it creates the tail
HeadNode::HeadNode()
{
myNext = new TailNode;
}
// Nothing comes before the head so just
// pass the data on to the next node
Node * HeadNode::Insert(Data * theData)
{
myNext = myNext->Insert(theData);
return this;
}
// I get all the credit and do none of the work
class LinkedList
{
public:
LinkedList();
~LinkedList() { delete myHead; }
void Insert(Data * theData);
void ShowAll() { myHead->Show(); }
private:
HeadNode * myHead;
};
// At birth, i create the head node
// It creates the t
超级会员免费看
订阅专栏 解锁全文
824

被折叠的 条评论
为什么被折叠?



