-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
111 lines (94 loc) · 1.85 KB
/
main.cpp
File metadata and controls
111 lines (94 loc) · 1.85 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include "HashTable.h"
#include "Map.h"
#include "Common.h"
enum class Menu
{
Exit = 0,
Add = 1,
Remove = 2,
RemoveAllValues = 3,
Find = 4
};
int main()
{
MapHashTable* map = new MapHashTable;
InitHashTable(map->Map);
int userChoose;
bool endProgramm = false;
std::string key;
std::string value;
while (!endProgramm)
{
ShowHashTable(map->Map);
ShowMap(map);
std::cout << "\nAdd (1)\n"
<< "Remove *from the begining* (2)\n"
<< "Remove *all values from the key* (3)\n"
<< "Find (4)\n"
<< "Exit (0)\n"
<< "\nEnter command: ";
std::cin >> userChoose;
switch (static_cast<Menu>(userChoose))
{
case Menu::Add:
{
key = GetKey();
std::cout << "Enter value: " << std::endl;
getline(std::cin, value);
if (IsNeedToRehashing(map->Map))
{
Rehashing(map->Map);
}
if (Push(map, key, value) == 0)
{
std::cout << "Done :)" << std::endl;
system("pause");
break;
}
std::cout << "Pair (key: " + key + " value: " + value
+ ") already include in map" << std::endl;
system("pause");
break;
}
case Menu::Remove:
{
key = GetKey();
std::cout << Pop(map, key) << std::endl;
system("pause");
break;
}
case Menu::RemoveAllValues:
{
key = GetKey();
PopAllValues(map, key);
std::cout << "Done !)" << std::endl;
system("pause");
break;
}
case Menu::Find:
{
key = GetKey();
std::cout << "Result: "<< FindMapItem(map, key) << std::endl;
system("pause");
break;
}
case Menu::Exit:
{
endProgramm = true;
break;
}
default:
{
std::cout << "Unknown command, choose another" << std::endl;
std::cin.clear();
std::cin.ignore(32767, '\n');
system("pause");
break;
}
}
system("cls");
}
DeleteMapHashTable(map);
return 0;
}