0% found this document useful (0 votes)
14 views10 pages

Assignm NT 1 Dsa

Uploaded by

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

Assignm NT 1 Dsa

Uploaded by

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

#include<iostream>

#include<string.h>

using namespace std;

class hashfunction

typedef struct hash

long key;

char name[100];

}hash;

hash h[100];

public:

hashfunction();

void insert();

void display();

int find(long);

void delete1(long);

};

hashfunction::hashfunction()

int i;

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

h[i].key=-1;

strcpy(h[i].name,"NULL");
}

void hashfunction::delete1(long key)

int index=find(key);

if(index==-1)

cout<<"\n\t key not found";

else

h[index].key=-1;

strcpy(h[index].name,"NULL");

cout<<"\n \t key is deleted";

int hashfunction::find(long k)

int i;

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

if(h[i].key==k)

cout<<"\n \t"<<h[i].key<<"is found at"<<i<<"location with


name"<<h[i].name;

return i;
}

if(i==10)

return -1;

void hashfunction::display()

int i;

cout<<"\n \t\t\t key\t\tname";

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

cout<<"\n \th["<<i<<"]\t"<<h[i].key<<"\t\t"<<h[i].name;

void hashfunction::insert()

char ans,n[11],ntemp[10];

long k,temp;

int hi,cnt=0,flag=0,i;

do
{

if(cnt>=10)

cout<<"\n \t hash table is full";

break;

cout<<"\n enter a telephone no.:";

cin>>k;

cout<<"enter the client name";

cin>>n;

hi=k%10;

if(h[hi].key==-1)

h[hi].key=k;

strcpy(h[hi].name,n);

else

for(i=hi+1;i<10;i++)

if(h[i].key==-1)

h[i].key=k;

strcpy(h[i].name,n);

flag=1;
break;

for(i=0;i<hi && flag==0;i++)

if(h[i].key==-1)

h[i].key=k;

strcpy(h[i].name,n);

break;

flag=0;

cnt++;

cout<<"\n \t....do you want to insert more key";

cin>>ans;

}while(ans=='y'||ans=='Y');

main()

long k;
int ch,index;

char ans;

hashfunction obj;

do

cout<<"\n\t********dictionary(ADT)********";

cout<<"\n \t1.insert\n\t2.display\n \t3.find\n\t4.delete\n\t5.exit";

cout<<"\n \t.....enter your choice";

cin>>ch;

switch(ch)

case 1:obj.insert();

break;

case 2:

obj.display();

break;

case 3:

cout<<"\n\t enter a kety which you want to search:";

cin>>k;

index=obj.find(k);

if(index==-1)

cout<<"\n \t key not found";

}
break;

case 4:

cout<<"\n \t enter a key which you want to delete";

cin>>k;

obj.delete1(k);break;

case 5:

break;

cout<<"\n \t .... do you want to continue main menu:";

cin>>ans;

}while(ans=='y'||ans=='Y');

********dictionary(ADT)********

1.insert

2.display

3.find

4.delete

5.exit

.....enter your choice 11

enter a telephone no.:1234567890

enter the client namegayatri

....do you want to insert more keyy


enter a telephone no.:9372963096

enter the client nameNamrata

....do you want to insert more keyy

enter a telephone no.:9076890982

enter the client namesakshi

....do you want to insert more keyn

.... do you want to continue main menu:y

********dictionary(ADT)********

1.insert

2.display

3.find

4.delete

5.exit

.....enter your choice2

key name

h[0] 1234567890 gayatri

h[1] -1 NULL

h[2] 9076890982 sakshi


h[3] -1 NULL

h[4] -1 NULL

h[5] -1 NULL

h[6] 9372963096 Namrata

h[7] -1 NULL

h[8] -1 NULL

h[9] -1 NULL

.... do you want to continue main menu:y

********dictionary(ADT)********

1.insert

2.display

3.find

4.delete

5.exit

.....enter your choice3

enter a kety which you want to search:1234567890

1234567890is found at0location with namegayatri

.... do you want to continue main menu:y

********dictionary(ADT)********

1.insert

2.display
3.find

4.delete

5.exit

.....enter your choice4

enter a key which you want to delete1234567890

1234567890is found at0location with namegayatri

key is deleted

.... do you want to continue main menu:

You might also like