-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
118 lines (87 loc) · 2.51 KB
/
main.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
#include<stdio.h>
#include<stdlib.h>
#include "linked_list.h"
#include "stack_queue.h"
#include "hash_table.h" // after linked list
/****** main test ******/
void test_LinkedList(void)
{
printf("Linked list implementation test: \n\n");
Node* node;
node = list_CreateNode(0);
List * list = list_CreateList(node);
printf("New list node created at %p \n", list);
list_printList(list);
printf("Inserting new value -1 to head: \n");
list_InsertValueToHead(list, -1);
printf("New list is: \n");
list_printList(list);
node = list_CreateNode(-3);
printf("Inserting new node (-3) to head: \n");
list_InsertNodeToHead(list, node);
printf("New list is: \n");
list_printList(list);
printf("Inserting new value 1 to tail: \n");
list_InsertValueToTail(list, 1);
printf("New list is: \n");
list_printList(list);
node = list_CreateNode(3);
printf("Inserting new node (3) to tail: \n");
list_InsertNodeToTail(list, node);
printf("New list is: \n");
list_printList(list);
printf("Searching for -1 ... \n");
node = list_Search(list, -1);
printf("Insert -2 before -1. \n");
list_InsertValueBeforeNode(list, node, -2);
printf("New list is: \n");
list_printList(list);
printf("Searching for 2 ... \n");
printf(" %p \n", list_Search(list, 2));
printf("Insert 2 after 1. \n");
node = list_Search(list, 1);
list_InsertValueAfterNode(list, node, 2);
printf("New list is: \n");
list_printList(list);
printf("Delete head: ");
list_DeleteHead(list);
printf("New list is: \n");
list_printList(list);
printf("Delete tail: ");
list_DeleteTail(list);
printf("New list is: \n");
list_printList(list);
printf("Find 0 and delete \n");
node = list_Search(list, 0);
list_Delete(list, node);
printf("New list is: \n");
list_printList(list);
}
int main()
{
test_LinkedList();
// test hash table
printf("Hash Table test: \n");
int i = 0;
int hashSize = 10;
printf("Creating Hash Table of size %d \n", hashSize);
HashTable* hashTable = malloc(sizeof(HashTable));
ht_Create(hashTable, hashSize);
for (i=0; i<hashSize; i++){
printf("<Key, Val> of node head %d is <%d, %d> \n", i,
(hashTable->htNodeHead+i)->key,
(hashTable->htNodeHead+i)->value);
}
for (i=0; i<hashSize*2; i++){
ht_Insert(hashTable, i, 100+i);
}
ht_Search(hashTable, 12); //present
ht_Search(hashTable, 32); // not present
ht_PrintTable(hashTable, 7);
ht_Delete(hashTable, 7);
ht_PrintTable(hashTable, 7);
ht_PrintTable(hashTable, 16);
ht_Delete(hashTable, 16);
ht_PrintTable(hashTable, 16);
return 1;
}