keychain.h

来自「一本全面剖析C++数据结构算法的书籍」· C头文件 代码 · 共 32 行

H
32
字号
#ifndef KeyedChain_#define KeyedChain_// file keychain.h// chains with keys#include "echain.h"template<class T>class KeyedChain : public Chain<T> {   public:      bool Delete(T& x); // delete x      ChainNode<T> * First() const {return first;}};template<class T>bool KeyedChain<T>::Delete(T& x){// Delete element matching x.   ChainNode<T> *i = first, *p = 0;   // search for match   for (; i && i->data != x; i = i->link) p = i;   if (!i) throw BadInput(); // no match   // match found in node i   x = i->data; // return matching element   if (p) p->link = i->link; // i is not first node   else first = i->link; // i is first node   delete i;   return *this;}#endif

⌨️ 快捷键说明

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