?? node.h
字號:
#include <stdlib.h>
#include <iostream.h>
template <class T>
class Node
{
Node<T> * next; //next 是下一個結點的地址
public:
T data; // the data is public
Node(const T& item, Node<T>* ptrnext=NULL);
// list modification methods
void InsertAfter(Node<T> *p);
Node<T> * DeleteAfter(void);
// obtain the address of the next node
Node<T> * NextNode(void) const;
};
//有參構造函數
template <class T>
Node<T>::Node(const T& item, Node<T>* ptrnext) :
data(item), next(ptrnext){ }
// return value of private member next
template <class T>
Node<T>* Node<T>::NextNode(void) const
{
return next;
}
// insert a node p after the current one
template <class T>
void Node<T>::InsertAfter(Node<T> *p)
{
// p points to successor of the current
// node, and current node points to p.
p->next = next;
next = p;
}
// delete the node following current and return its address
template <class T>
Node<T>* Node<T>::DeleteAfter(void)
{ // save address of node to be deleted
Node<T>* tempPtr = next;
// if there isn't a successor, return NULL
if (next == NULL) return NULL;
// current node points to successor of tempPtr.
next = tempPtr->next;
// return the pointer to the unlinked node
return tempPtr;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -