Task
Task
if (head == NULL) {
head = newNode;
return;
}
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
void remove (int id)
{
if(head==0)
{
cout<<"ID doesnot exist!"<<endl;//epmty list
}
if (head->data.id == id)
{
Node *ptr=head;
head=head->next;
delete ptr;
return;
}
Node* current = head;
while (current->next) {
if (current->next->data.id == id) {
Node* temp = current->next;
current->next = temp->next;
delete temp;
return;
}
current = current->next;
}
}
void updatesalary(const int& salary, int id) {
if(head==0)
{
cout<<"List is empty, cannot modify salary"<<endl;
}
Node* ptr = head;
while (ptr) {
if (ptr->data.id == id) {
ptr->data.salary = salary;
return;
}
ptr = ptr->next;
}
}
void display() {
Node* temp = head;
while (temp) {
temp->data.display();
cout << endl << endl;
temp = temp->next;
}
}
void clear() {
while (head) {
Node* temp = head;
head = head->next;
delete temp;
}
}
};
int main() {
employe emp1(101, "John Doe", "12345", 50000.0, 2000.0);
employe emp2(102, "Jane Smith", "67890", 60000.0, 2500.0);
employe emp3(103, "Bob Johnson", "54321", 55000.0, 2100.0);
employe emp4(104, "Alice Brown", "98765", 70000.0, 3000.0);
employe emp5(105, "Eva White", "45678", 52000.0, 1900.0);
linked_list l;
l.insert(emp1);
l.insert(emp2);
l.insert(emp3);
l.insert(emp4);
l.insert(emp5);
cout<<"Before updation: "<<endl;
l.display();
//cout<<"kk";
l.updatesalary(605000, 102);
l.display();
cout<<endl;
l.remove(104);
l.display();
return 0;
}