c_13_1.cpp

来自「C++应用教程原码,里面包含该书中有十三章内容的代码,详细具体」· C++ 代码 · 共 34 行

CPP
34
字号
#include "stdafx.h"
#include <string>
#include "List.h"
#include "Hash.h"
#include <iostream>
#include <fstream>
using namespace std;

template <class Type>
int hashTable <Type> ::hashFunction(const Type &k)
{
	int len =k.length(), key;
    if (len<=1)
      key = k[0];
    else
      key = k[0] + k[len-1];
   return (key% numBuckets);
}
void main()
{   string word;
    hashTable <string> a(20,10);
	fstream file;
	file.open("sample.txt",ios::in);
    if(!file)
    { cerr << "文件打开失败"<<endl;
     exit(-1);
    }
	while (file >> word)
       a.insert(word);
	if(a.find("help")) cout <<"找到单词help"<<endl;
	if(!a.find("teacher")) cout <<"没有找到单词teacher"<<endl;
	 file.close();
	 cin.get(); //等待结束,以便调测程序,可以删除
}

⌨️ 快捷键说明

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