You are on page 1of 3

TASK1:

/*

* 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.

*/

package hashing_technique;

import java.util.Scanner;

/**

* @author lab-6

*/

public class Hashing_technique {

//Linear probing,Division method

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Scanner sc=new Scanner(System.in);

System.out.println("Enter no of Elements to store :");

int size=sc.nextInt();

int arr[]=new int[size];

int mod=arr.length;
for(int i=0;i<arr.length;i++){

System.out.println("Enter Integer :");

int temp=sc.nextInt();

int S=temp%mod;

while( arr[S]!=0){

S++;

if(S>arr.length){

S=0;

arr[S]=temp;

for(int i=0;i<arr.length;i++){

System.out.println("The element "+i+" is " +arr[i]);

System.out.println("Enter Element to search !!");

int search=sc.nextInt();

boolean flag=false;

for(int i=0;i<arr.length;i++){

if(arr[i]==search){

System.out.println("The "+search+" is found at index "+i);

flag=true;

if (flag=false){

System.out.println("Element not found!!");

}
}

You might also like