-
Notifications
You must be signed in to change notification settings - Fork 0
/
chain.cpp
78 lines (60 loc) · 2.03 KB
/
chain.cpp
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
#include <cstdlib>
#include <iostream>
#include "LinkedList.hpp"
#include "Dictionary.hpp"
#include "ChainedMap.hpp"
#include "LinkedList.hpp"
#include <limits>
#include <exception>
#include <string>
using namespace std;
int main()
{
int no;
// cout<<"Enter the size of the dictionary : ";
// cin>>no;
cs202::ChainedMap <int,int> A;
int key, value;
int choice;
while (1)
{
cout<<"Enter your choice: "<<endl;
cout<<"----------------------"<<endl;
cout<<"1.Insert element into the table"<<endl;
cout<<"2.Search element from the key"<<endl;
cout<<"3.Delete element of a key"<<endl;
cout<<"4.Print the table"<<endl;
cout<<"5.Current length of the table"<<endl;
cout<<"6.Exit"<<endl;
cin>>choice;
switch(choice)
{
case 1: {cout<<"Enter element to be inserted: ";
cin>>value;
cout<<"Enter key at which element to be inserted";
cin>>key;
A.put(key,value);
break;}
case 2: {cout<<"Enter key of the element to be searched: ";
cin>>key;
cout<<"Element at key "<<key<<" : ";
try
{value = A.get(key);}
catch(int error)
{cout<<"there is no element on such key"<<endl;}
cout<<value<<endl;
break;}
case 3: {cout<<"Enter key of the element to be deleted: ";
cin>>key;
A.remove(key);
break;}
case 4: {A.print();
break;}
case 5: {cout<<"The current length of the table : "<<A.get_size()<<endl;
break;}
case 6: { exit(0);
break;}
}
}
return 0;
}