-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSeperateChaining.c
51 lines (46 loc) · 1 KB
/
SeperateChaining.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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <windows.h>
typedef struct numlist{
int number;
struct numlist *next;
}numlist;
void inserttochain(int key, numlist **head){
numlist *ptr = (*head);
numlist *node = (numlist*)malloc(sizeof(numlist));
node->number = key;
node->next = NULL;
if(*head == NULL){
*head = node;
}
else{
while(ptr->next !=NULL){
ptr = ptr->next;
}
ptr->next = node;
}
}
int main(){
numlist *hasht[10];
int i;
for(i=0; i<10; i++){
hasht[i]=NULL;
}
while(1){
system("cls");
for(i=0; i<10; i++){
numlist *ptr = hasht[i];
printf("[%d]->",i);
while(ptr!=NULL){
printf("(%d)",ptr->number);
ptr = ptr->next;
}
printf("\n");
}
int inputkey;
scanf("%d",&inputkey);
inserttochain(inputkey, &hasht[inputkey%10]);
}
return 0;
}