forked from rjkalash/hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashing.cpp
78 lines (75 loc) · 1013 Bytes
/
hashing.cpp
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
#include<iostream>
#include<conio.h>
#include<cstdlib>
#define max 10
using namespace std;
void insert();
void display();
int main()
{
int ch;
while(1)
{
cout<<"\n1.Insert Element\n2.Display\n3.Exit\n";
cin>>ch;
switch(ch)
{
case 1:
insert();
break;
case 2:
display();
break;
case 3:
exit(0);
default:
cout<<"Wrong Choice :)";
}
}
}
struct node
{
int data;
struct node *next;
};
struct node *head[max]={NULL},*c;
void insert()
{
int i,key,ele;
cout<<"\nEnter element\n";
cin>>ele;
i=ele%max;
struct node *newnode=new node();
newnode->data=ele;
newnode->next = NULL;
if(head[i]==NULL)
head[i]=newnode;
else
{
c=head[i];
while(c->next!=NULL)
{
c=c->next;
}
c->next=newnode;
}
}
void display()
{
int i;
for(i=0;i<max;i++)
{
cout<<"\n";
if(head[i]==NULL)
{
continue;
}
else
{
for(c=head[i];c!=NULL;c=c->next)
{
cout<<c->data<<"\t";
}
}
}
}