Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhhf96
C-Plus-Plus-TheAlgorithms
提交
a8b28254
C
C-Plus-Plus-TheAlgorithms
项目概览
zhhf96
/
C-Plus-Plus-TheAlgorithms
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
C-Plus-Plus-TheAlgorithms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a8b28254
编写于
7月 29, 2020
作者:
K
Krishna Vedala
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use named namespace
上级
e09637fb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
12 deletion
+24
-12
hashing/linear_probing_hash_table.cpp
hashing/linear_probing_hash_table.cpp
+22
-11
hashing/quadratic_probing_hash_table.cpp
hashing/quadratic_probing_hash_table.cpp
+2
-1
未找到文件。
hashing/linear_probing_hash_table.cpp
浏览文件 @
a8b28254
...
...
@@ -9,9 +9,14 @@
#include <iostream>
#include <vector>
namespace
{
// keep the code local to this file by assigning them to an unnamed
// namespace
/**
* @addtogroup Open Addressing
* @{
* @namespace linear_probing
* @brief An implementation of hash table using [linear
* probing](https://en.wikipedia.org/wiki/Linear_probing) algorithm.
*/
namespace
linear_probing
{
// fwd declarations
using
Entry
=
struct
Entry
;
bool
putProber
(
const
Entry
&
entry
,
int
key
);
...
...
@@ -204,7 +209,11 @@ void removalInfo(int key) {
std
::
cout
<<
"New table: "
;
display
();
}
}
// namespace
}
// namespace linear_probing
using
linear_probing
::
Entry
;
using
linear_probing
::
table
;
using
linear_probing
::
totalSize
;
/** Main function
* @returns 0 on success
...
...
@@ -216,7 +225,8 @@ int main() {
table
=
std
::
vector
<
Entry
>
(
totalSize
);
bool
loop
=
true
;
while
(
loop
)
{
system
(
"pause"
);
std
::
cout
<<
"
\n
Press a key to continue...
\n
"
;
std
::
cin
.
get
();
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"PLEASE CHOOSE -"
<<
std
::
endl
;
std
::
cout
<<
"1. Add key. (Numeric only)"
<<
std
::
endl
;
...
...
@@ -230,18 +240,18 @@ int main() {
case
1
:
std
::
cout
<<
"Enter key to add = "
;
std
::
cin
>>
key
;
addInfo
(
key
);
linear_probing
::
addInfo
(
key
);
break
;
case
2
:
std
::
cout
<<
"Enter key to remove = "
;
std
::
cin
>>
key
;
removalInfo
(
key
);
linear_probing
::
removalInfo
(
key
);
break
;
case
3
:
{
std
::
cout
<<
"Enter key to search = "
;
std
::
cin
>>
key
;
Entry
entry
=
table
[
linearProbe
(
key
,
true
)];
if
(
entry
.
key
==
notPresent
)
{
Entry
entry
=
table
[
linear
_probing
::
linear
Probe
(
key
,
true
)];
if
(
entry
.
key
==
linear_probing
::
notPresent
)
{
std
::
cout
<<
"Key not present"
;
}
break
;
...
...
@@ -249,10 +259,11 @@ int main() {
case
4
:
std
::
cout
<<
"Enter element to generate hash = "
;
std
::
cin
>>
key
;
std
::
cout
<<
"Hash of "
<<
key
<<
" is = "
<<
hashFxn
(
key
);
std
::
cout
<<
"Hash of "
<<
key
<<
" is = "
<<
linear_probing
::
hashFxn
(
key
);
break
;
case
5
:
display
();
linear_probing
::
display
();
break
;
default:
loop
=
false
;
...
...
hashing/quadratic_probing_hash_table.cpp
浏览文件 @
a8b28254
...
...
@@ -250,7 +250,8 @@ int main() {
table
=
std
::
vector
<
Entry
>
(
totalSize
);
bool
loop
=
true
;
while
(
loop
)
{
system
(
"pause"
);
std
::
cout
<<
"
\n
Press a key to continue...
\n
"
;
std
::
cin
.
get
();
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"PLEASE CHOOSE -"
<<
std
::
endl
;
std
::
cout
<<
"1. Add key. (Numeric only)"
<<
std
::
endl
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录