-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDirect_Addreesing_Tables.cpp
110 lines (105 loc) · 2.17 KB
/
Direct_Addreesing_Tables.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
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
/*
* C++ Program To Implement Direct Addressing Tables
*/
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
/*
* Table Declaration
*/
struct table
{
string english;
int key;
table()
{}
table( int k, string e )
{
english=e;
key = k;
}
};
/*
* Insertion of element at a key
*/
void INSERT( table T[], table x )
{
T[ x.key ] = x;
}
/*
* Deletion of element at a key
*/
void DELETE( table T[], table x )
{
T[ x.key ] = table(0, "");
}
/*
* Searching of element at a key
*/
table SEARCH( table T[], int k )
{
return T[ k ];
}
/*
* Main Contains Menu
*/
int main()
{
int i, key, ch;
string str;
table T[65536];
table x;
for(i = 0; i < 65536;i++)
T[i] = table(0,"");
while(1)
{
cout<<"\n-------------------------------------"<<endl;
cout<<"\nOperations on Direct Addressing Table"<<endl;
cout<<"\n-------------------------------------"<<endl;
cout<<"1.Insert element into the key"<<endl;
cout<<"2.Delete element from the table"<<endl;
cout<<"3.Search element into the table"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>ch;
switch(ch)
{
case 1:
{
string str1 = "";
cout<<"Enter the key value: ";
cin>>key;
cout<<"Enter the string to be inserted: ";
cin.ignore();
getline(cin, str);
INSERT(T, table(key, str));
break;
}
case 2:
cout<<"Enter the key of element to be deleted: ";
cin>>key;
x = SEARCH(T, key);
DELETE(T, x);
break;
case 3:
cout<<"Enter the key of element to be searched: ";
cin>>key;
x = SEARCH(T, key);
if(x.key == 0)
{
cout<<"No element inserted at the key"<<endl;
continue;
}
cout<<"Element at key "<<key<<" is-> ";
cout<<"\""<<x.english<<"\""<<endl;
break;
case 4:
exit(1);
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}