-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhasing_double.cpp
More file actions
executable file
·155 lines (123 loc) · 2.04 KB
/
hasing_double.cpp
File metadata and controls
executable file
·155 lines (123 loc) · 2.04 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
using namespace std;
int hash_function( int data,int i );
void insert ( int data ,int a[]) {
/*int key = hash_function( data );
if (a [ key ] == NULL ){
a [ key ] = data;
key++;
}
else {
while ( a [key] != NULL ) {
key++;
}
a[ key ] = data;
}*/
for ( int i =0; i<11;i++){
int j = hash_function(data,i);
if ( a[j]==NULL) {
a[j]=data;
break;
}
else {
if(i==10){
cout << "hashfxn overflow";
}
}
}
}
int hash_function( int data,int i) {
/* int a = data % 10;
if ( a >=0){
return a;
}
else {
return (-a);
}*/
int h1=data%11;
int h2=data%10 + 1;
int t = (h1 + i*h2) % 11;
return t;
}
/*
int remove( int data , int a[]) {
int key = hash_function(data);
if ( a [ key ] == data ) {
a [ key ] = -1;
}
else {
while ( a[key] != data ){
key ++;
// if ( a[key] == NULL ){
// break;
// }
}
a[ key ] = -1;
}
}
*/
int show ( int a [] ){
for ( int i=0;i<11 ;i++){
cout << "Array[ " << i << " ] = "<< a[i] << endl;
}
}
void search ( int a[], int data){
/* int key = hash_function(data);
if ( a[key] == data){
cout << "Number found at index :-" << key << endl;
}
else{
while ( a [key] !=data ) {
key++;
if ( a[ key ] == NULL){
break;
}
}
cout << "Number found at index :-" << key << endl;
}
*/
}
int main ()
{
int a[100];
int i = 0;
int check=1;
int c;
int num;
while ( check == 1 ) {
cout << "1-insert\n";
cout << "2-delete\n";
cout << "3-search\n";
cout << "4-show \n";
cout << "Enter choice-\n";
cin >> c;
switch ( c ) {
case 1:
cout << "Enter the 11 random Values"<< endl;
for ( int i=0;i<11;i++){
a[i]=NULL;
}
for ( int i=0;i<11;i++){
cin >> num;
insert ( num , a );
cout << "--- Content After Insetion-\n";
show ( a );
}
break;
case 2:
cin >> num;
// remove(num , a);
break;
case 3:
cin >> num;
search ( a, num);
break;
case 4:
show ( a );
break;
}
cout << "1 To continue:";
cin >> check;
}
return 0;
}