C++程序代写实现HashSet class

专业程序代写(QQ:928900200)

Implement a HashSet class for elements of type string.
It has the following functions: 
bool add(const string &)
bool contains(const string &) const
int size() const
In this exercise, you need to implement some of the above functions, as well as several internal functoins: 
int find(const string & e) const
void resize(int capacity2)
bool contains(const string & e) const
Hint:
The function find(e) finds the first position starting from p=h%N, which is either empty or equal to e. That is, find(e) should look like the following: 
int find(const string & e) const {
int p = hashIndex(e);
while (true) {
if (…) return p;
p = (p + 1) % capacity;
}
}
EXAMPLE INPUT 
apple
orange
banana
apple
orange

apple
watermelonEXAMPLE OUTPUT 
3
true
false

主程序

#include <iostream> 
#include <string> 
using namespace std;

////////////////////////// 
// Interfaces 
//

template <typename E> 
class Set 

public: 
virtual bool add(const E &) = 0; 
virtual bool contains(const E &) const = 0; 
virtual int size() const = 0; 
};

template <typename E> 
class HashFunction 

public: 
virtual int getHashCode(const E & e) const = 0; 
};

///////////////////////// 
// hash-function 
//

class StringHashFunction : public HashFunction<string> 

public: 
int getHashCode(const string & text) const { 
int code = 0; 
for (int i = 0; i < text.size(); ++ i) { 
int code1 = text[i]; 
code1 = code1 « (i * 8 % 24); 
code = code ^ code1; 

return code; 

};

///////////////////////// 
// your class 
//

class HashSet : public Set<string> 

private:

const StringHashFunction hashFunction;

class Entry 

public: 
string element; 
bool isInUse;

Entry() { 
isInUse = false; 

};

Entry * entries;

int capacity; 
int count;

void initialize(int capacity2) { 
count = 0; 
capacity = capacity2; 
entries = new Entry[capacity]; 
}

void assign(const HashSet & set2) { 
count = set2.count; 
capacity = set2.capacity; 
entries = new Entry[capacity]; 
for (int i = 0; i < capacity; ++ i) { 
entries[i] = set2.entries[i]; 

}

public:

HashSet() { 
initialize(2); 
}

~HashSet() { 
delete [] entries; 
}

HashSet(const HashSet & set2) { 
assign(set2); 
}

HashSet & operator = (const HashSet & set2) { 
delete [] entries; 
assign(set2); 
return (*this); 
}

private:

int hashIndex(const string & e) const { 
int hashCode = hashFunction.getHashCode(e); 
return hashCode % capacity; 
}

int find(const string & e) const;

void resize(int capacity2);

public:

bool add(const string & e) { 
int index = find(e); 
if (entries[index].isInUse) { 
return false; 

entries[index].element = e; 
entries[index].isInUse = true; 
++ count; 
if (count > capacity / 2) { 
resize(capacity * 2); 

return true; 
}

bool contains(const string & e) const;

int size() const { 
return count; 
}

};

#include “source”

int main() { 
HashSet set; 
for (int i = 0; i < 5; ++ i) { 
string text; 
cin » text; 
set.add(text); 

cout « set.size() « endl; 
for (int i = 0; i < 2; ++ i) { 
string text; 
cin » text; 
if (set.contains(text)) { 
cout « “true” « endl; 

else { 
cout « “false” « endl; 

}

}

C++程序代写实现HashSet class的更多相关文章

  1. 如何鉴别程序抄袭c语言程序代写

    如何鉴别程序抄袭:如何鉴别一份程序代码是抄袭另一份程序.输入:两个C语言源程序文件 输出:抄袭了多少?给出最相似的片段,判断是谁抄袭了谁? 提示:首先进行统一规范化排版,去掉无谓的空格.空行,然后比对 ...

  2. c编写程序完成m名旅客和n辆汽车的同步程序代写

    jurassic公园有一个恐龙博物馆和一个公园,有m名旅客和n辆汽车,每辆汽车仅能允许承载一名旅客.旅客在博物馆参观一阵,然后排队乘坐旅行车.当一辆车可用时,他载入一名旅客,再绕花园行驶任意长的时间. ...

  3. 实验教学管理系统 c语言程序代写源码下载

    问题描述:实验室基本业务活动包括:实验室.班级信息录入.查询与删除:实验室预定等.试设计一个实验教学管理系统,将上述业务活动借助计算机系统完成. 基本要求: 1.必须存储的信息 (1)实验室信息:编号 ...

  4. 模拟游客一天的生活与旅游java程序代写源码

    在某个城市的商业区里,有一家首饰店,一家饭店,一家面馆,一家火锅店,一家银行,一家当铺 现在有一群来自四川的游客,一群陕西的游客,一群上海的游客,和以上各店家的工作人员在此区域里,请模拟他们一天的生活 ...

  5. 基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写

    基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写 专业程序代写服务(QQ:928900200) 随着社会的进步.服务行业的服务水平不断发展与提高,宾馆.酒店.旅游等服务行业的信息量和工作 ...

  6. 程序代写, CS代写, 代码代写, CS编程代写, java代写, python代写, c++/c代写, R代写, 算法代写, web代写

    互联网一线工程师程序代写 微信联系 当天完成 查看大牛简介特色: 学霸代写,按时交付,保证原创,7*24在线服务,可加急.用心代写/辅导/帮助客户CS作业. 客户反馈与评价 服务质量:保证honor ...

  7. CS代码代写, 程序代写, java代写, python代写, c/c++代写,csdaixie,daixie,作业代写,代写

    互联网一线工程师程序代写 微信联系 当天完成特色: 互联网一线工程师 24-48小时完成.用心代写/辅导/帮助客户CS作业. 客户反馈与评价 服务质量:保证honor code,代码原创.参考课程sl ...

  8. C++代写,代写C++,C++程序代写,C++ assignment代写

    C++代写,代写C++,C++程序代写 关于C++代写,我们的涉猎范围: C++数据结构.算法题目 C++操作系统os题目 C++网络编程networking题目 C++ Linux题目 C++ Wi ...

  9. 程序设计实践C++ 程序代写(QQ 928900200)

    程序设计实践 采用C++作为编程语言. 设计开发一个“学生信息”管理系统.该系统模拟数据库管理系统(DBMS)的功能,为用户提供数据存储.查找的能力. 该系统存储的学生信息包括: 学号.姓名.性别.语 ...

随机推荐

  1. opencv 边缘羽化,边缘过渡

    原地址:http://blog.csdn.net/sogarme/article/details/12942971 当把前景和背景分开时,黑色代表背景,白色代表前景,如下图1—记作img1 为了平滑过 ...

  2. 有时候碰到String赋值就出错,原因有三

    1. String所在的对象,根本就不存在(不是String不存在,而是它所属的类对象不存在) 2. 增加一个String作为类元素后,运行直接就崩溃.一次又一次找原因,结果发现,只需要完全重编译就行 ...

  3. Java学习笔记4

    Java学习笔记4 1. JDK.JRE和JVM分别是什么,区别是什么? 答: ①.JDK 是整个Java的核心,包括了Java运行环境.Java工具和Java基础类库. ②.JRE(Java Run ...

  4. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 站点设置

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第3章节--SharePoint 2013 开发者工具 站点设置         你应该熟悉(假设还咩有)的SharePo ...

  5. 在web网页中正确使用图片格式

    今天又看了一遍淘宝平四分享的PPT,以前转载网址:http://blog.sina.com.cn/s/blog_995c1f6301017fd2.html

  6. 算法起步之Kruskal算法

    原文:算法起步之Kruskal算法 说完并查集我们接着再来看这个算法,趁热打铁嘛.什么是最小生成树呢,很形象的一个形容就是铺自来水管道,一个村庄有很多的农舍,其实这个村庄我们可以看成一个图,而农舍就是 ...

  7. 更改Oracle实例的字符集

    (1).数据库服务器字符集select * from nls_database_parameters 来源于props$,是表示数据库的字符集. (2).服务端字符集环境select * from n ...

  8. loj1245(数学)

    传送门:Harmonic Number (II) 题意:求sum=n/1+n/2+n/3+...+n/n.(n<2^31) 分析:在一定的区间内n/i的值是一定的,因此要跳过这段区间来加速求解. ...

  9. 散文说python半篇——景观三元论与盖茨比的对话

    今天, 天气晴朗,风和日丽: 我事实上在说谎-- 爱说谎事实上是我的天性 上个礼拜四我就用景观三元论说了非常多谎话.然后一头大象自己上吊了. 了不起的大象啊,盖茨比也要从坟墓里爬出来了吧, 陈年旧事, ...

  10. xcode6 iOS sdk8.1隐藏系统状态栏

    在代码项目(uzplayer)从iOS6升级到iOS8之后,头发如今视频播放器有.系统状态栏后面的背景: 这样就会导致有的时候按下Donebutton,或者拖滑块没有效果 所以,我们须要想个办法.把这 ...