-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassg7_Hash.cpp
84 lines (74 loc) · 1.37 KB
/
assg7_Hash.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
#include<string.h>
using namespace std;
int i,key[50],n,c[50];
class hash_table
{
public:
int prn,rno;
string name,add;
float per;
void declare();
void table();
void accept();
}h[50];
void hash_table::declare()
{
cout<<"\n Enter the number of student records you want to store = ";
cin>>n;
cout<<"\n enter the keys : ";
for(i=0;i<n;i++)
{
cin>>key[i];
}
for(i=0;i<50;i++)
{
h[i].prn=-1;
c[i]=0;
}
}
void hash_table::table()
{
cout<<"\n PRN\tRollnO\tName\tAdd\tPer\tChain";
for(i=0;i<50;i++)
{
cout<<"\n"<<h[i].prn<<"\t"<<h[i].rno<<"\t"<<h[i].name<<"\t"<<h[i].add<<"\t"<<h[i].per<<"\t"<<c[i];
}
}
void hash_table::accept()
{
int no,pos;
for(i=0;i<n;i++)
{
no=key[i]%10;
pos=no;
do
{
if(h[no].prn==-1)
{
h[no].prn=key[i];
cout<<"\n Enter the Rollno, Name, Add, Per";
cin>>h[no].rno>>h[no].name>>h[no].add>>h[no].per;
break;
}
else
{
no++;
c[pos]=no;
if(no>50)
{
no=0;
}
}
}while(no<50);
}
}
int main()
{
hash_table obj;
obj.declare();
obj.table();
obj.accept();
obj.table();
return 0;
}