dictionary.h
来自「卡内基梅隆大学SSD5数据结构的实验内容包括实验1-5的所有要提交的文件」· C头文件 代码 · 共 61 行
H
61 行
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include<fstream>
#include "hashset.h"
#include "hashset.cpp"
using namespace std;
class hash_function
{
public:
hash_function() {}
unsigned int operator()( const string& s ) const {
// Complete definition
int hashval=0;
for(int i=0;i<s.length();i++)
{
hashval=37*hashval+s[i];
}
return hashval;
}
};
class equality
{
public:
equality() {}
bool operator()( const string& A, const string& B ) const {
return (A == B);
}
};
class Dictionary: public HashSet<string, hash_function, equality> {
// Complete definition
public:
Dictionary(char* filename)
{
string word;
ifstream inf(filename);
while(inf.good())
{
inf>>word;
/*if(!inf.good())
return;*/
this->insert(word);
}
}
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?