-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesthash.c
168 lines (155 loc) · 3.66 KB
/
testhash.c
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
156
157
158
159
160
161
162
163
164
165
166
167
168
#define SepChain
// data formating
// add comments
#ifdef SepChain
#include "hashsep.h"
#endif
#ifdef QuadProb
#include "hashquad.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define constant 25
struct ListNode
{
unsigned long int mobile;
unsigned long int home;
char first_name[constant];
char last_name[constant];
char company_name[constant];
Position Next;
};
int main( )
{
clock_t start, end;
HashTable H;
Position P=NULL;
int i = 0;
int j = 0;
int CurrentSize;
int options = 0;
char c_opt[5];
char num[constant];
double runtime;
struct ListNode f;
char *path = "C:\\zmyFIles\\UET_SEMESTERS\\semester4\\data_structures_and_algorithms\\Project\\contacts.csv";
H = InitializeTable(CurrentSize = 70);
start = clock();
Load(path, H);
end = clock();
runtime = (end - start) / (double)CLOCKS_PER_SEC;
printf("runTime = %.20f\n", runtime);
while (options != 6)
{
puts("1. Retrieve\n2. Insertions\n3. Deletion\n4. Edit\n5. Print\n6. Exit");
printf("Your Choice: ");
scanf_s("%s", c_opt,5);
options = atoi(c_opt);
getchar();
if (options == 1)//Retrieve options
{
puts("Enter name of person");
scanf_s("%s", f.first_name,constant);
getchar();
start = clock();
Retrieve(f.first_name, H, 'r');
end = clock();
runtime = (end - start) / (double)CLOCKS_PER_SEC;
printf("runTime = %.20f\n", runtime);
getchar();
}
else if (options == 2) // Insert Options
{
do
{
puts("Enter first name of person");
scanf_s("%s", f.first_name, constant);
getchar();
//_strlwr_s(f.first_name = strdup(f.first_name), strlen(f.first_name)
puts("Enter second name of person");
scanf_s("%s", f.last_name , constant);
getchar();
P=Find(f.first_name, f.last_name, H); // finds duplicates
if (P != NULL)
puts("Contact already present");
} while (P != NULL);
puts("Enter work place");
scanf_s("%s", f.company_name, constant);
getchar();
do
{
puts("Enter mobile number");
scanf_s("%s", num,constant); // mobile number does not accepts characters
getchar();
if (j = hasAlphabets(num)) {
puts("Invalid Number");
}
else
break;
} while (j);
f.mobile = atoi(num);
do
{
puts("Enter home number");
scanf_s("%s", num,constant); // phone number does not accepts characters
getchar();
if (j = hasAlphabets(num)) {
puts("Invalid Number");
}
else
break;
} while (j = 1);
f.home = atoi(num);
start = clock();
Insert(&f, H);
end = clock();
runtime = (end - start) / (double)CLOCKS_PER_SEC;
printf("runTime = %.20f\n", runtime);
getchar();
}
else if (options == 3)
{
puts("Enter first name of person");
scanf_s("%s", f.first_name, constant); // DELETE
getchar();
Delete(f.first_name, H);
getchar();
}
else if (options == 4)
{
puts("Enter first name of person");
scanf_s("%s", f.first_name, constant); // edit
getchar();
update(f.first_name, H);
getchar();
}
else if (options == 5)
{
start = clock();
Sort(H);
end = clock();
runtime = (end - start) / (double)CLOCKS_PER_SEC;
printf("runTime = %.20f\n", runtime);
getchar(); // Prints sorted list
}
else if (options == 6)
{
break;
}
else
{
puts("Invalid Choice\nPress any Key to continue");
getchar();
}
system("cls");
if (TableElements(H) > 2 * TableSize(H)) // Adjusts Load factor
H = Rehash(H);
}
path = "C:\\zmyFIles\\UET_SEMESTERS\\semester4\\data_structures_and_algorithms\\Project\\contacts1.csv";
write(path, H);
printf( "End of program.\n" );
getchar();
return 0;
}