-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.c
More file actions
48 lines (42 loc) · 1.16 KB
/
Copy pathsearch.c
File metadata and controls
48 lines (42 loc) · 1.16 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
#include "search.h"
Guest binarySearch(Guest* guest, char* name, int low, int high)
{
while (low <= high) {
int mid = low + (high - low) / 2;
if (strcmp(guest[mid].name, name) == 0)
return guest[mid];
if (strcmp(guest[mid].name, name) < 0)
low = mid + 1;
else
high = mid - 1;
}
Guest guestNotFound;
strcpy(guestNotFound.name, "NULL");
return guestNotFound;
}
Guest* binarySearchPtr(Guest* guest, char* name, int low, int high)
{
while (low <= high) {
int mid = low + (high - low) / 2;
if (strcmp(guest[mid].name, name) == 0)
return &guest[mid];
if (strcmp(guest[mid].name, name) < 0)
low = mid + 1;
else
high = mid - 1;
}
Guest *guestNotFound = (Guest*) malloc(sizeof(Guest));
strcpy(guestNotFound->name, "NULL");
return guestNotFound;
}
Guest searchByRoomId(Guest* guest, char roomId, int size)
{
for (int i = 0; i<size; i++) {
if(guest[i].roomId == roomId) {
return guest[i];
}
}
Guest guestNotFound;
strcpy(guestNotFound.name, "NULL");
return guestNotFound;
}