Backuadmkaa Ss Ignment Day
Backuadmkaa Ss Ignment Day
// MEMBERS NAME ID
#include <iostream>
struct employee{
char firstName[25];
char lastName[25];
char empID[10];
int age;
int yearsOfServies;
float salary;
employee* next;
employee* previous;
};
employee* start=NULL;
cout<<"____________________________"<<endl;
cout<<"____________________________"<<endl;
cin>>node->firstName;
cin>>node->empID;
cin>>node->age;
cin>>node->yearsOfServies;
cin>>node->salary;
node->next=NULL;
node->previous=NULL;
if(start == NULL){
start=node;
tail=node;
}else{
tail->next=node;
node->previous=tail;
tail=node;
cout<<"____________________________"<<endl;
cout<<"____________________________"<<endl;
cin>>node->firstName;
if(t1->previous==s1){
break;
s1=s1->next;
t1=t1->previous;
s1->next=n;
n->previous=s1;
n->next=t1;
t1->previous=n;
employee* temp;
if(tail==NULL){
cout<<"Empty list"<<endl;
}else if(tail->previous==NULL){
tail=NULL;
start=NULL;
delete tail;
delete start;
}else{
temp=tail->previous;
tail->previous=NULL;
temp->next=NULL;
delete tail;
tail=temp;
}
employee* temp;
if(start==NULL){
cout<<"Empty list"<<endl;
}else if(start->next==NULL){
tail=NULL;
start=NULL;
delete tail;
delete start;
}else{
temp=start->next;
start->next=NULL;
temp->previous=NULL;
delete start;
start=temp;
char name[25];
cin>>name;
if(start==NULL){
} else if(start->next==NULL){
if(strcmp(start->firstName,name)==0){
start=NULL;
delete start;
}else{
}else{
while(temp!=NULL){
if(strcmp(temp->firstName,name)==0){
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
temp->next=NULL;
temp->previous=NULL;
delete temp;
result=1;
temp=temp->next;
if(result==0){
char ID[10];
cin>>ID;
if(start==NULL){
} else if(start->next==NULL){
if(strcmp(start->empID,ID)==0){
start=NULL;
delete start;
}else{
}else{
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
temp->next=NULL;
temp->previous=NULL;
delete temp;
result=1;
temp=temp->next;
if(result==0){
}
void deleteNthNode(){ // DELETE THE NTH NODE
int n,counter=1,size=0;
cout<<endl<<"**************************************************"<<endl;
cin>>n;
while(n<=0) // VALIDATING N
cout << "Invalid input! Please enter a positive integer." << endl;
cin>>n;
if(start==NULL){
} else if(start->next==NULL){
if(n==1){
start=NULL;
delete start;
cout<<endl<<"Succesfully deleted!!!"<<endl;
}else{
}else{
employee* temp=start;
while(temp!=NULL){
if(counter==n){
start->previous=NULL;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
tail=temp->previous;
tail->next=NULL;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
}else{
temp->previous->next=temp->next;
temp->next->previous=temp->previous;
delete temp;
cout<<endl<<"Succesfully deleted!!!"<<endl;
counter++;
size++;
temp=temp->next;
if(n>size){
employee* result=NULL;
cin>>ID;
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
result=temp;
temp=temp->next;
if(start==NULL){
}else if(result==NULL){
}else{
cout<<endl<<"************************************"<<endl;
cin>>result->firstName;
cout<<"-------------Name UPDATED------------"<<endl;
int average;
int sum=0;
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
sum+=i->age;
size++;
if(size!=0){
average=sum/size;
cout<<endl<<"*****************************************"<<endl;
}else{
float average;
float sum=0;
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
sum+=i->salary;
size++;
if(size!=0){
average=sum/size;
cout<<endl<<"*****************************************"<<endl;
}else{
}
}
int size=0;
for(employee* i=start;i!=NULL;i=i->next){
size++;
if(size!=0){
cout<<endl<<"*****************************************"<<endl;
}else{
int count=0;
int n;
cout<<endl<<"*****************************************"<<endl;
cin>>n;
while(n<=0) // VALIDATING N
cout << "Invalid input! Please enter a positive integer." << endl;
cin>>n;
}
for(employee* i=start;i!=NULL;i=i->next){
if(i->yearsOfServies==n){
count++;
if(start==NULL){
}else if(count==0){
}else{
char ID[10];
employee* result=NULL;
cin>>ID;
while(temp!=NULL){
if(strcmp(temp->empID,ID)==0){
result=temp;
temp=temp->next;
}
if(start==NULL){
}else if(result==NULL){
}else{
cout<<endl<<"************************************"<<endl;
char name[25];
employee* result=NULL;
cout<<endl<<"************************************"<<endl;
cin>>name;
while(temp!=NULL){
if(strcmp(temp->firstName,name)==0){
result=temp;
cout<<endl<<"************************************"<<endl;
temp=temp->next;
if(start==NULL){
}else if(result==NULL){
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->age>max->age){
max=i;
if(start=NULL){
}else{
cout<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl<<endl;
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->yearsOfServies>max->yearsOfServies){
max=i;
if(start=NULL){
}else{
cout<<endl<<"******************************************"<<endl;
cout<<"*****************************************"<<endl<<endl;
employee* min=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->age<min->age){
min=i;
if(start=NULL){
}else{
cout<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl<<endl;
employee* max=start;
for(employee*i=start;i!=NULL;i=i->next){
if(i->salary>max->salary){
max=i;
if(start=NULL){
} else{
cout<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl<<endl;
employee* min = i;
min = j;
if (min != i) {
float tempSalary;
// Swap empID
strcpy(tempID, i->empID);
strcpy(i->empID, min->empID);
strcpy(min->empID, tempID);
// Swap firstName
strcpy(tempName, i->firstName);
strcpy(i->firstName, min->firstName);
strcpy(min->firstName, tempName);
// Swap salary
tempSalary = i->salary;
i->salary = min->salary;
min->salary = tempSalary;
strcpy(tempLName, i->lastName);
strcpy(i->lastName, min->lastName);
strcpy(min->lastName, tempLName);
// Swap age
tempAge = i->age;
i->age = min->age;
min->age = tempAge;
// Swap yearsOfServies
tempYears = i->yearsOfServies;
i->yearsOfServies = min->yearsOfServies;
min->yearsOfServies = tempYears;
}
cout<<endl<<"List Sorted successfully by NAME!"<<endl;
void BubbleSortListByName() {
if (start == NULL){
return;
}else if(start->next==NULL) {
return;
}else {
employee* current;
float tempSalary;
// Swap empID
strcpy(tempID, current->empID);
strcpy(current->empID, current->next->empID);
strcpy(current->next->empID, tempID);
// Swap firstName
strcpy(tempName, current->firstName);
strcpy(current->firstName, current->next->firstName);
strcpy(current->next->firstName, tempName);
// Swap salary
tempSalary = current->salary;
current->salary = current->next->salary;
current->next->salary = tempSalary;
// Swap lastName
strcpy(tempLName, current->lastName);
strcpy(current->lastName, current->next->lastName);
strcpy(current->next->lastName, tempLName);
// Swap age
tempAge = current->age;
current->age = current->next->age;
current->next->age = tempAge;
// Swap yearsOfService
tempYears = current->yearsOfServies;
current->yearsOfServies = current->next->yearsOfServies;
current->next->yearsOfServies = tempYears;
}
}
void SelectionSortListByAge() {
if (start == NULL){
return;
}else if(start->next==NULL) {
return;
}else {
employee* min = i;
min = j;
if (min != i) {
float tempSalary;
// Swap empID
strcpy(tempID, i->empID);
strcpy(i->empID, min->empID);
strcpy(min->empID, tempID);
// Swap firstName
strcpy(tempName, i->firstName);
strcpy(i->firstName, min->firstName);
strcpy(min->firstName, tempName);
// Swap salary
tempSalary = i->salary;
i->salary = min->salary;
min->salary = tempSalary;
strcpy(tempLName, i->lastName);
strcpy(i->lastName, min->lastName);
strcpy(min->lastName, tempLName);
// Swap age
tempAge = i->age;
i->age = min->age;
min->age = tempAge;
// Swap yearsOfServies
tempYears = i->yearsOfServies;
i->yearsOfServies = min->yearsOfServies;
min->yearsOfServies = tempYears;
}
void display3OldestEmp(){ // DISPLAYING THE 3 OLDEST EMPLOYEE FROM LIST
int counter=0;
SelectionSortListByAge();
cout<<endl<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=tail;counter<3;i=i->previous){
cout<<endl<<"_________________________________"<<endl;
counter++;
int counter=0;
int n,size=0;
cout<<endl<<"*****************************************"<<endl;
cin>>n;
for(employee* i=start;i!=NULL;i=i->next){
size++;
}
if(size<n){
return;
SelectionSortListByAge();
cout<<endl<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=tail;counter<n;i=i->previous){
cout<<endl<<"_________________________________"<<endl;
counter++;
void display(){
cout<<endl<<endl<<"**************************************"<<endl;
cout<<"**************************************"<<endl;
for(employee*i=start;i!=NULL;i=i->next){
cout<<endl<<"_________________________________"<<endl;
cout<<"Employee Full Name: "<<i->firstName<<" "<<i->lastName<<endl;
int main()
int n;
cin>>n;
for(int i=0;i<n;i++){
insertAtEnd();
display();
return 0;