#include <iostream>
#include <string>
#include "Employee.h";
usingnamespace std;
#ifndef EMPLOYEELIST_H
#define EMPLOYEELIST_H
class EmployeeList
{
private:
Employee *head;//employee pointer(head pointer)
public:
//default constructor
EmployeeList()
{
head = NULL;
}
//Add a node to the end of the list
void AddNode(int id, string fName, string lName)
{
Employee *node = new Employee(id,fName,lName);
//if memory was sucessfully allocated
if (node != NULL)
{
//if this is the first node to be added
//or if list is empty
if (head == NULL)
{
head = node;//make the first element
}
else
{ ///if the list is not empty
Employee *temp = head;
while(temp->getNext() != NULL)
{
temp = temp->getNext();//points temp to the next element
}
temp->setNext(node);//the end is reached we insert the element
}
}
else
{
cout << "Unable to create new node." << endl;
}
}
//display list
void displayList()
{
Employee *temp = head;
while (temp != NULL)
{
temp->display();//Employee's display method called here
temp = temp->getNext();
}
}
void bubbleSort(){
Employee*holder, *previous, *position;
Employee *temp = head;//assigns the head to a temporary pointer
EmployeeList *list;
Employee *previousnode = NULL;//set the previous node to point to null
while (temp != NULL)//while not the end of the list
{
for (holder=temp; holder!=NULL && holder->next!=NULL; holder=holder- >next){
previous = holder;
for(position=holder->next; position!=NULL; position=position->next){
if(position->getIdNumber()< previous->getIdNumber()){
previous = position;
}
}
temp = holder;
holder = previous;
head = holder;
previous = temp;
}
list->displayList();
}
}
};
#endif