forked from AlmiranteFuchs/hashing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyht.c
More file actions
63 lines (55 loc) · 1.35 KB
/
myht.c
File metadata and controls
63 lines (55 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Main
// Author: B. Fuchs, M. Telles
#include "libs/hash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
// Create a new hash table
hash_table *t1 = new_hash_table(11);
hash_table *t2 = new_hash_table(11);
// Read from stdin
char *line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, stdin)) != -1)
{
// Get the key and value in the line
char *key = strtok(line, " ");
char* value_tmp = strtok(NULL, "");
int value = 0;
if (value_tmp != NULL)
{
value = atoi(value_tmp);
}
// See what command it is
if (strcmp(key, "i") == 0)
{
// Insert the value into the hash table
insert_hash(t1, t2, value);
}
else if (strcmp(key, "r") == 0)
{
// Delete the value from the hash table
// delete (t1, t2, value);
remove_hash(t1, t2, value);
}
else if (strcmp(key, "p") == 0)
{
get_ordered_hashs(t1, t2);
return 0;
}
else
{
printf("Invalid command\n");
break;
}
}
// Prints the hash tables
get_ordered_hashs(t1, t2);
destroy_hash_table(t1);
destroy_hash_table(t2);
free(line);
return 0;
}