-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHashing.java
More file actions
69 lines (64 loc) · 1.55 KB
/
Hashing.java
File metadata and controls
69 lines (64 loc) · 1.55 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//Created by sidhant
//27/03/2017
//Hashing in combination with modulo and chainig
import java.util.*;
class node
{
int value;
node next;
}
public class Hashing
{
public static void main (String args[])
{
Scanner in=new Scanner (System.in);
System.out.println("Enter number of input");
int n=in.nextInt();
node m[]=new node[n];
for (int i=0;i<n;i++)
{
m[i]=new node();
}
int flag=0;
System.out.println("Enter "+n+" numbers");
for (int i=0;i<n;i++)
{
int k=in.nextInt();
node p=m[k%n];
while (p.next!=null)
{
p=p.next;
}
node a =new node();
a.value=k;
p.next=a;
a.next=null;
}
for (int i=0;i<n;i++)
{
node b=m[i];
while(b!=null)
{
System.out.print(b.value+" ");
b=b.next;
}
}
System.out.println("Here 0 are untouched lists");
System.out.println("Enter number to be searched");
int t=in.nextInt();
node b=m[t%n];
while (b!=null)
{
if (b.value==t)
{
flag=1;
break;
}
b=b.next;
}
if (flag==1)
System.out.println("Number Found");
else
System.out.println("Number not found");
}
}