-
Notifications
You must be signed in to change notification settings - Fork 0
/
INCOMPLETE_HASHTABLE
66 lines (54 loc) · 1.25 KB
/
INCOMPLETE_HASHTABLE
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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define SIZE 20
struct listStruct{
int number;
struct listStruct *next;
};
typedef struct listStruct list;
list* allocateNode();
void insertNumber(list **l, int num);
void displayAllElements(list **l);
int main(void)
{
list *newList[SIZE];
for(int i = 0; i < SIZE; i++){
newList[i] = allocateNode();
newList[i]->number = -1;
newList[i]->next = NULL;
}
insertNumber(newList, 10);
insertNumber(newList, 10);
insertNumber(newList, 2);
insertNumber(newList, 3);
insertNumber(newList, 4);
insertNumber(newList, 5);
insertNumber(newList, 6);
displayAllElements(newList);
return 0;
}
list* allocateNode()
{
return (list *) malloc(sizeof(list));
}
void displayAllElements(list **l)
{
printf("\nThe Hashtable is : \n");
for(int i = 0; i < SIZE; i++){
list *temp = l[i];
while(temp){
printf("%d--->",temp->number);
temp = temp->next;
}
printf("\n");
}
}
void insertNumber(list **l, int num)
{
int bucketNum = num % SIZE;
list *temp = allocateNode();
temp->number = num;
temp->next = l[bucketNum];
l[bucketNum] = temp;
}