?? node.h
字號:
/* 鏈表結點
* QA Pass
*/
#ifndef NODE_CLASS
#define NODE_CLASS
#include <stdlib.h>
template <class T>
class Node
{
private:
// next 為指向下一結點的指針
Node<T> *next;
public:
// data 為公有成員
T data;
// 構造函數
Node(const T& item, Node<T> *ptrnext = NULL);
// 修改表的方法
void InsertAfter(Node<T> *p);
Node<T> *DeleteAfter(void);
// 取得下一結點的指針
Node<T> *NextNode(void) const;
};
// 構造函數。初始化數據及指針成員
template <class T>
Node<T>::Node(const T& item, Node<T> *ptrnext):
data(item), next(ptrnext)
{}
// 返回私有成員 next 的值
template <class T>
Node<T> *Node<T>::NextNode(void) const
{
return next;
}
// 在當前結點之后插入結點 p
template <class T>
void Node<T>::InsertAfter(Node<T> *p)
{
// p 指向當前結點的后繼結點,然后將當前結點指向 p
p->next = next;
next = p;
}
// 刪除當前結點的后繼結點并返回其指針
template <class T>
Node<T> *Node<T>::DeleteAfter(void)
{
// 若沒有后繼結點,返回 NULL
if (next == NULL)
return NULL;
// 保存指向被刪除結點的指針
Node<T> *tempPtr = next;
// 使當前結點指向 tempPtr 的后繼結點
next = tempPtr->next;
// 返回被刪除結點的指針
return tempPtr;
}
#endif // NODE_CLASS
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -