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

📄 skip.cpp

📁 data structures, algorithms and Application书的源代码
💻 CPP
字号:
// test skip list class

#include <iostream.h>
#include "skip.h"

class element {
   friend void main(void);
   public:
      operator long() const {return key;}
      element& operator =(long y)
      {key = y; return *this;}
   private:
      int data;
      long key;
};

void main(void)
{
   SkipList<element, long> S(10001, 100, 0.5);
   element e;
   int i, n = 20;
   for (i = 1; i <= n; i++) {
      e.data = i; e.key = 2*i;
      S.Insert(e);}
   S.Output();
   for (i=1; i <= n+1; i++) {
      e.data = n+i; e.key = 2*i-1;
      try {S.Insert(e);}
      catch (BadInput)
       {cout << "Unable to insert duplicate " << e << endl;}
      catch (NoMem)
       {cout << "Not enough memory to insert " << e << endl;}
      }
   
   S.Output();
   for (i = 1; i <= n+1; i++) {
      long k = 2*i-1;
      try {S.Delete(k,e);
         cout << "Deleted " << e.key << "  " << e.data << endl;}
      catch (BadInput)
         {cout << "Delete of " << (2*i-1) << " failed" << endl;}
      }
   S.Output();
}

⌨️ 快捷键说明

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