⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnode.h

📁 模式识别的C均值聚类算法,用C语言编写的,可运行
💻 H
字号:
#ifndef CIRCULAR_NODE_CLASS
#define CIRCULAR_NODE_CLASS

template <class T>
class CNode
{
    private:
    	// circular link to the next node
        CNode<T> *next;
    public:
    	// data is public 
        T data;
        
		// constructors
        CNode(void);
        CNode (const T& item);
        
        // list modification methods
        void InsertAfter(CNode<T> *p);
        CNode<T> *DeleteAfter(void);
        
        // obtain the address of the next node
        CNode<T> *NextNode(void) const;
};

// constructor that creates an empty list and
// leaves the data uninitialized. use for header
template <class T>
CNode<T>::CNode(void)
{
	// initialize the node so it points to itself
    next = this;
}

// constructor that creates an empty list and initializes data
template <class T>
CNode<T>::CNode(const T& item)
{
	// set node to point to itself and initialize data
    next = this;
    data = item;
}
  
// return pointer to the next node
template <class T>
CNode<T> *CNode<T>::NextNode(void) const
{
    return next;
}

// insert a node p after the current one
template <class T>
void CNode<T>::InsertAfter(CNode<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>
CNode<T> *CNode<T>::DeleteAfter(void)
{
	// save address of node to be deleted
    CNode<T> *tempPtr = next;
    
	// if next is the address of current object (this), we are
	// pointing to ourself. We don't delete ourself! return NULL
    if (next == this)
        return NULL;
        
	// current node points to successor of tempPtr.
    next = tempPtr->next;
    
	// return the pointer to the unlinked node
    return tempPtr;
}

#endif  // CIRCULAR_NODE_CLASS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -