Mehran Dsa Assign 2
Mehran Dsa Assign 2
Class: BScs-3B
Assignment no 2
#include <iostream>
#include <string>
class Employee {
public:
int id;
string name;
string dob;
string phone;
string address;
Employee(int empId, const string& empName, const string& empDob, const string& empPhone, const string& empAddress)
};
class Node {
public:
Employee data;
Node* next;
};
class EmpLinkedList {
private:
Node* head;
public:
EmpLinkedList() : head(nullptr) {}
bool IsEmpty() {
Node* Front() {
return head;
Node* Back() {
if (IsEmpty()) {
return nullptr;
current = current->next;
return current;
void Print_List() {
cout << "ID: " << current->data.id << ", Name: " << current->data.name << ", DOB: " << current->data.dob
<< ", Phone: " << current->data.phone << ", Address: " << current->data.address << endl;
current = current->next;
}
void AddFront(Employee emp) {
newNode->next = head;
head = newNode;
if (IsEmpty()) {
head = newNode;
return;
lastNode->next = newNode;
void DeleteFront() {
if (!IsEmpty()) {
head = head->next;
delete temp;
void DeleteBack() {
if (!IsEmpty()) {
if (head->next == nullptr) {
delete head;
head = nullptr;
return;
}
Node* current = head;
current = current->next;
delete current->next;
current->next = nullptr;
if (current->data.id == empId) {
return current;
current = current->next;
return nullptr;
void Modify(int empId, const string& newName, const string& newDob, const string& newPhone, const string& newAddress)
{
if (empNode != nullptr) {
empNode->data.name = newName;
empNode->data.dob = newDob;
empNode->data.phone = newPhone;
empNode->data.address = newAddress;
}
void Add(Employee emp) {
newNode->next = head;
head = newNode;
return;
current = current->next;
newNode->next = current->next;
current->next = newNode;
if (IsEmpty()) {
return;
if (head->data.id == empId) {
head = head->next;
delete temp;
return;
if (current->next == nullptr) {
return;
current->next = current->next->next;
delete temp;
int Count() {
int count = 0;
count++;
current = current->next;
return count;
};
int choice;
do {
cout << "9. Modify an Employee data (Name, Date of Birth, Phone, address)\n";
switch (choice) {
case 1: {
if (frontNode != nullptr) {
cout << "Front Employee's Info: ID=" << frontNode->data.id << ", Name=" << frontNode->data.name << endl;
} else {
break;
case 2: {
if (backNode != nullptr) {
cout << "Back Employee's Info: ID=" << backNode->data.id << ", Name=" << backNode->data.name << endl;
} else {
break;
case 3:
break;
case 4: {
int id;
break;
case 5: {
int id;
break;
case 6:
empList.DeleteFront();
break;
case 7:
empList.DeleteBack();
break;
case 8: {
int id;
if (empNode != nullptr) {
cout << "Employee found: ID=" << empNode->data.id << ", Name=" << empNode->data.name << endl;
} else {
break;
case 9: {
int id;
break;
case 10: {
int id;
break;
case 11: {
int id;
empList.Delete(id);
break;
case 12:
cout << "Number of Employees: " << empList.Count() << endl;
break;
case 0:
break;
default:
int main() {
EmpLinkedList employeeList;
displayMenu(employeeList);
return 0;