Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-hashtable
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-hashtable
Commits
ff652d82
Commit
ff652d82
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add manual mode
parent
ae801549
Branches
develop
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+47
-29
47 additions, 29 deletions
main.c
with
47 additions
and
29 deletions
main.c
+
47
−
29
View file @
ff652d82
...
...
@@ -5,40 +5,58 @@
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
"hashtable.h"
int
main
()
{
hm
*
hashmap
=
hm_create
(
10
);
hm_set
(
hashmap
,
"Key1"
,
"Value1"
);
hm_set
(
hashmap
,
"Key2"
,
"Value1"
);
hm_set
(
hashmap
,
"Key1"
,
"Value2"
);
hm_set
(
hashmap
,
"Key3"
,
"Value1"
);
hm_set
(
hashmap
,
"Key4"
,
"FOUR"
);
hm_set
(
hashmap
,
"Key1"
,
"Value3"
);
hm_set
(
hashmap
,
"Key5"
,
"I think it's good now"
);
hm_set
(
hashmap
,
"Key6"
,
"6"
);
hm_set
(
hashmap
,
"Key7"
,
"7"
);
hm_set
(
hashmap
,
"Key8"
,
"8"
);
hm_set
(
hashmap
,
"Key9"
,
"9"
);
hm_set
(
hashmap
,
"Key27"
,
"MORE ?"
);
hm_set
(
hashmap
,
"Key10"
,
"Is this the end ?"
);
srand
(
0
);
hm
*
hashmap
=
hm_create
(
5
);
printf
(
"Value of %s : %s
\n
"
,
"Key1"
,
hm_get
(
hashmap
,
"Key1"
));
printf
(
"
Value of %s : %s
\n
"
,
"Key2"
,
hm_get
(
hashmap
,
"Key2"
)
);
printf
(
"Value of %s : %s
\n
"
,
"Key3"
,
hm_get
(
hashmap
,
"Key3"
))
;
printf
(
"Value of %s : %s
\n
"
,
"Key4"
,
hm_get
(
hashmap
,
"Key4"
)
);
printf
(
"Value of %s : %s
\n
"
,
"Key5"
,
hm_get
(
hashmap
,
"Key5"
));
printf
(
"
Value of %s : %s
\n
"
,
"Key6"
,
hm_get
(
hashmap
,
"Key6"
)
);
printf
(
"Value of %s : %s
\n
"
,
"Key7"
,
hm_get
(
hashmap
,
"Key7"
))
;
printf
(
"Value of %s : %s
\n
"
,
"Key8"
,
hm_get
(
hashmap
,
"Key8"
));
printf
(
"Value of %s : %s
\n
"
,
"Key9"
,
hm_get
(
hashmap
,
"Key9"
))
;
printf
(
"Value of %s : %s
\n
"
,
"Key10"
,
hm_get
(
hashmap
,
"Key10"
))
;
while
(
true
)
{
printf
(
"
Add (1), Delete (2), Search (3), Print (4), Exit (5)...
\n
"
);
int
selection
;
scanf
(
"%d"
,
&
selection
);
if
(
selection
<
1
||
selection
>
5
)
{
printf
(
"
Bad input, try again.
\n
"
);
continue
;
}
char
phone
[
10
]
;
char
name
[
10
]
;
hm_print
(
hashmap
);
hm_rm
(
hashmap
,
"Key1"
);
hm_print
(
hashmap
);
hm_rm
(
hashmap
,
"Key10"
);
hm_print
(
hashmap
);
if
(
selection
==
1
)
{
printf
(
"Phone :
\n
"
);
scanf
(
"%s"
,
phone
);
printf
(
"Name :
\n
"
);
scanf
(
"%s"
,
name
);
char
*
p
=
strdup
(
phone
);
char
*
n
=
strdup
(
name
);
hm_set
(
hashmap
,
p
,
n
);
hm_print
(
hashmap
);
free
(
n
);
free
(
p
);
}
if
(
selection
==
2
)
{
printf
(
"Phone to delete :
\n
"
);
scanf
(
"%s"
,
phone
);
hm_rm
(
hashmap
,
phone
);
hm_print
(
hashmap
);
}
if
(
selection
==
3
)
{
printf
(
"Phone to search :
\n
"
);
scanf
(
"%s"
,
phone
);
char
*
p
=
strdup
(
phone
);
char
*
name
=
hm_get
(
hashmap
,
p
);
if
(
name
!=
NULL
)
{
printf
(
"%s
\n
"
,
name
);
}
}
if
(
selection
==
4
)
{
hm_print
(
hashmap
);
}
if
(
selection
==
5
)
{
break
;
}
}
hm_destroy
(
&
hashmap
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment