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

📄 hashprobe.cpp

📁 ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c
💻 CPP
字号:
#include <time.h>#include <algae/config.h>#include <iostream>#include <cstdlib>#include <sstream>#include <string>#include <algae/algae.h>using namespace std;string itos (int i){  ostringstream str;  str << i;  return str.str();}#include "hashset.h"using namespace std;void promptForInput(const char* prompt, int& input){  string reply;  bool OK = false;  while (!OK)    {     algae->promptForInput (prompt, reply);     const char* replystr = reply.c_str();     istringstream in (replystr);     OK = !!(in >> input);    }}struct StringHash {  int operator() (const string& s) const {return s.length();}};typedef hash_set<string, 8, StringHash> HashTable;HashTable* set;bool firstTime = true;void init(){  if (firstTime)    {      firstTime = false;      set = new HashTable;      set->show();    }}void hashInsert(){  init();  string v;  algae->promptForInput("String to insert", v);  bool inserted = set->insert (v);  if (!inserted)    cout << "Unable to insert " << v << " into table." << endl;  Visible::unHighlightAll();}void hashSearch(){  init();  string v;  algae->promptForInput("String to search for", v);  int k = set->count (v);  cout << "count() returned " << k << endl;  Visible::unHighlightAll();}void hashErase(){  init();  string v;  algae->promptForInput("String to remove", v);  set->erase (v);  Visible::unHighlightAll();}void hashClear(){  init();  set->clear ();  Visible::unHighlightAll();}AlgAE* algae;int main (int nargs, char** args){  time_t dummy;  srand (time(&dummy));    algae = new AlgAE(nargs, args);    algae->menuItem("Insert", hashInsert);  algae->menuItem("Erase", hashErase);  algae->menuItem("Search (count)", hashSearch);  algae->menuItem("-", 0);  algae->menuItem("Clear", hashClear);    algae->run ("Hashing - linear probing",	      "Hash table with linear probing adapted for AlgAE animation by\n"	      "  Steven J. Zeil, Old Dominion University"	      );    delete algae;    return 0;}

⌨️ 快捷键说明

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