Vous êtes sur la page 1sur 12

kinnaird college for women

submitted to:-
ma'am rida hijab
submitted by:-
Sadaf Ashfaq
Sherbano

code
#include<iostream>
#include<string>

using namespace std;

struct employee

int E_ID;

string name;

int age;

char gender;

string address;

string pnumb;

string department;

string dop;

string designation;

double salary;

employee *next;

};

struct hashnode

employee *E[10];

int tables = 10;

int key;

public:

hashnode()

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


{

E[i] = NULL;

void inserthash(employee* value)

value->next = NULL;

key = hashfun(value->E_ID);

if (E[key] == NULL)

E[key] = value;

else

Insert(value);

void Insert(employee* value)

int hashv = hashfun(value->E_ID);

employee* prev = NULL;

employee* entry = E[hashv];

while (entry != NULL)

prev = entry;

entry = entry->next;

prev->next = value;

value->next = NULL;

bool search(int id)


{

int i = hashfun(id);

employee* temp = E[i];

if (temp != NULL)

while (temp->E_ID != id)

temp = temp->next;

if (temp != NULL && temp->E_ID == id)

return true;

else

return false;

else

return false;

void Del(int id)

int i = hashfun(id);

employee * T = E[i];
employee* Prev = nullptr;

if (E[i] != nullptr)

if (E[i]->next == nullptr && E[i]->E_ID == id)

E[i] = nullptr;

else

while (T != nullptr)

if (T->E_ID == id)

if (Prev == nullptr)

E[i] = E[i]->next;

delete T;

return;

else if (T->next == nullptr)

delete T;

Prev->next = nullptr;

return;
}

else

Prev->next = T->next;

T = nullptr;

return;

Prev = T;

T = T->next;

void display()

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

if (E[i] != NULL)

employee* temp = E[i];


while (temp != NULL)

cout << "ID: " << temp->E_ID << "\nName: " <<
temp->name << "\nAge: " << temp->age << "\nGender: " << temp->gender <<
"\nAddress: " << temp->address << "\nPhone Number: " << temp->pnumb <<
"\nDepartment> " << temp->department << "\nDate of appointment> " << temp->dop <<
"\nDesignation> " << temp->designation << "\nSalary> " << temp->salary;

temp = temp->next;

cout << endl;

int hashfun(int V)

return V % tables;

};

int main()

string name, address, designation, pnumb, department, dop;

hashnode H;

employee e;
char y;

int choice = 0;

cout << "enter 1 for insertion, 2 for search index, 3 for deletion";

while(choice != -1)

cout << "Enter the your choice";

cin >> choice;

if(choice == 1)

employee* e = new employee;

cout << "Enter employee record to be Added: " << endl;

cout << "enter Employee ID " << endl;

cin >> e->E_ID;

cout << "enter employee Name " << endl;

cin >> name;

//getline(cin, e->name);

cout << "enter employee Age " << endl;

cin >> e->age;

cout << "enter Gender (M/F) " << endl;

cin >> e->gender;

cout << "enter Address " << endl;

//getline(cin, e->address);

cin >> address;

cout << "enter Phone Number " << endl;

cin >> pnumb;

cout << "enter Department " << endl;;

cin >> department;

cout << "enter Date of appointment " << endl;


cin >> dop;

cout << "enter Designation " << endl;

cin >> designation;

//getline(cin, e->designation);

cout << "enter Salary> " << endl;

cin >> e->salary;

H.inserthash(e);

H.display();

if(choice == 2)

cout << "enter the index u want to search";

cin >> e.E_ID;

if (H.search(e.E_ID))

cout << "found-----";

else

cout << "Not found------";

if (choice == 3)

cin >> e.E_ID;

H.Del(e.E_ID);

H.display();

}
}

system("pause");

return 0;

output

Vous aimerez peut-être aussi