Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPLEMENT HASH TABLE #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions Competitive Coding/IMPLEMENTING HASH TABLE/Hashtable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/


import java.util.Scanner;
class Student{
int key;
String date;
String name;
Student next;
}
class Hashtable{
Scanner s=new Scanner(System.in);

Student node=new Student();
static Hashtable n=new Hashtable();
Student arr[]=new Student[10];
void Hash(){

System.out.print("enter input elements");
for(int x=0;x<5;x++) {
Student node=new Student();
node.key = s.nextInt();
node.date=s.next();
node.name=s.next();

int v= n.calculate(node.key);

if (arr[v]==null)
{
node.next=null;
arr[v]=node;
}
else
{
Student ptr;
ptr=arr[v];
while(ptr.next!=null){
ptr=ptr.next;
}
ptr.next=node;
node.next=null;
}
}
}
int calculate(int value)
{
int index =value%10;
return index;
}
void display()
{
for(int i=0;i<10;i++){
if(arr[i]==null)
{
System.out.println(arr[i]);
}
else
{
Student ptr=arr[i];
while(ptr!=null)
{
System.out.print("->"+ptr.key);

ptr=ptr.next;
}
System.out.println();
}
}}
public static void main(String args[])
{

n.Hash();
n.display();
}
}