using
System;
class
Node
{
public
string
Name;
public
long
Telephone;
public
int
Id;
public
Node()
{
Telephone = 0;
Id = 0;
}
}
class
Hashing
{
Node[] data =
new
Node[100];
string
n;
long
t;
int
i, index;
public
Hashing()
{
i = 0;
t = 0;
}
public
void
CreateRecord(
int
size)
{
i = 4;
n =
"XYZ Gupta"
;
t = 23451234;
Console.WriteLine(
"\nEnter id : "
+ i);
Console.WriteLine(
"Enter name : "
+ n);
Console.WriteLine(
"Enter telephone number : "
+ t);
index = i % size;
for
(
int
j = 0; j < size; j++)
{
if
(data[index] ==
null
)
{
data[index] =
new
Node { Id = i, Name = n, Telephone = t };
break
;
}
else
index = (index + 1) % size;
}
}
public
void
SearchRecord(
int
size)
{
int
index1, key, flag = 0;
key = 4;
Console.WriteLine(
"\nEnter record id to search : "
+ key);
index1 = key % size;
for
(
int
a = 0; a < size; a++)
{
if
(data[index1]?.Id == key)
{
flag = 1;
Console.WriteLine(
"\nRecord found:"
);
Console.WriteLine(
"\tID \tNAME \t\tTELEPHONE "
);
Console.WriteLine(
"\t"
+ data[index1].Id +
" \t"
+ data[index1].Name +
" \t"
+ data[index1].Telephone);
break
;
}
else
index1 = (index1 + 1) % size;
}
if
(flag == 0)
Console.WriteLine(
"\nRecord not found"
);
}
public
void
DeleteRecord(
int
size)
{
int
index1, key, flag = 0;
key = 4;
Console.WriteLine(
"\nEnter record id to delete : "
+ key);
index1 = key % size;
for
(
int
a = 0; a < size; a++)
{
if
(data[index1]?.Id == key)
{
flag = 1;
data[index1] =
null
;
Console.WriteLine(
"\nRecord deleted successfully"
);
break
;
}
else
index1 = (index1 + 1) % size;
}
if
(flag == 0)
Console.WriteLine(
"\nRecord not found"
);
}
public
void
UpdateRecord(
int
size)
{
int
index1, key, flag = 0;
key = 4;
Console.WriteLine(
"\nEnter record id to update : "
+ key);
index1 = key % size;
for
(
int
a = 0; a < size; a++)
{
if
(data[index1]?.Id == key)
{
flag = 1;
break
;
}
else
index1 = (index1 + 1) % size;
}
if
(flag == 1)
{
n =
"XYZ Agarwal"
;
t = 23413421;
data[index1].Name = n;
data[index1].Telephone = t;
Console.WriteLine(
"\nEnter name: \t\t\t"
+ n);
Console.WriteLine(
"Enter telephone number: \t"
+ t);
Console.WriteLine(
"Details updated: "
);
Console.WriteLine(
"\n\tID \tNAME \t\tTELEPHONE "
);
Console.WriteLine(
"\t"
+ data[index1].Id +
" \t"
+ data[index1].Name +
" \t"
+ data[index1].Telephone);
}
}
public
void
DisplayRecord(
int
size)
{
Console.WriteLine(
"\n\tID \tNAME \t\tTELEPHONE "
);
for
(
int
a = 0; a < size; a++)
{
if
(data[a] !=
null
)
{
Console.WriteLine(
"\t"
+ data[a].Id +
" \t"
+ data[a].Name +
" \t"
+ data[a].Telephone);
}
}
}
}
class
Program
{
static
void
Main()
{
int
size;
Hashing s =
new
Hashing();
size = 20;
Console.WriteLine(
"\n1.CREATE record "
);
s.CreateRecord(size);
Console.WriteLine(
"\n\n\n\n2.DISPLAY record "
);
s.DisplayRecord(size);
Console.WriteLine(
"\n\n\n\n3.SEARCH record"
);
s.SearchRecord(size);
Console.WriteLine(
"\n\n\n\n4.UPDATE record "
);
s.UpdateRecord(size);
Console.WriteLine(
"\n\n\n\n5.DELETE record "
);
s.DeleteRecord(size);
}
}