0% found this document useful (0 votes)
5 views6 pages

Hashing

hash

Uploaded by

anujgadekar688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Hashing

hash

Uploaded by

anujgadekar688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <iostream>

using namespace std;

class hashingtable

int static const size=10;

int table[size];

public:

hashingtable()

for(int i=0;i<size;i++)

table[i]=-1;

void insert_linearprobing(int key)

int result=key%size;

while(table[result]!=-1)

result=(result+1)%10;

table[result]=key;

void display()

{
for(int i=0;i<10;i++)

cout<<i<<" "<<table[i]<<endl;

void insert_quadraticprobing(int key)

int result=key%size;

int i=0;

while(table[result]!=-1)

i=i+1;

result=(result+(i*i))%size;

table[result]=key;

void search()

cout<<"enter element to search";

int x;

cin>>x;

int result=x%size;

int c=0;

while(table[result]!=x)
{

c=c+1;

result=(result+1)%size;

if(c==size)

break;

if(c==size)

cout<<"element is not present";

else

cout<<"element find at"<<result<<"th position after "<<c<<"comparisens";

void searchquadratic()

cout<<"enter element to search";

int x;

cin>>x;

int result=x%size;
int c=0;

int i=0;

while(table[result]!=x)

c=c+1;

i=i+1;

result=(result+(i*i))%size;

if(c==size)

break;

if(c==size)

cout<<"element is not present";

else

cout<<"element find at"<<result<<"th position after "<<c<<"comparisens";

};
int main()

hashingtable h;

int choice;

cout<<"enter 1 for liner hashing"<<endl;

cout<<"enter 2 for quadratic hashing"<<endl;

cin>>choice;

switch(choice)

case 1:

int x;

cout<<"enter the nuber of element you have to insert";

cin>>x;

cout<<"enter the element";

int y;

for(int i=0;i<x;i++)

cin>>y;

h.insert_linearprobing(y);

cout<<endl;

cout<<"all element in hasing table";

[Link]();
[Link]();

break;

case 2:

int x;

cout<<"enter the nuber of element you have to insert";

cin>>x;

cout<<"enter the element";

int y;

for(int i=0;i<x;i++)

cin>>y;

h.insert_quadraticprobing(y);

cout<<endl;

cout<<"all element in hasing table";

[Link]();

[Link]();

break;

return 0;

You might also like