node.h

来自「一个进行整数计算的C语言词法分析器」· C头文件 代码 · 共 49 行

H
49
字号
#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 + =
减小字号Ctrl + -
显示快捷键?