i wonder how to initialise some value in the linklist ,before insert the new node value?
#include <iostream>
#include <conio.h>
using namespace std;
struct employeeInfo
{
string name;
int id;
string department;
employeeInfo *next;
};
const int SIZE = 10;
employeeInfo employed[SIZE] = {{"Michael bay",1234,"Design"},{"Enrique",5678,"Production"},{"Fernando ",9012,"Management"}};
class List {
public:
List(void) { head = NULL; } // constructor
~List(void); // destructor
bool IsEmpty() { return head == NULL; }
employeeInfo* InsertEmployee(string ,int ,string );
void DisplayList(void);
private:
employeeInfo* head;
};
List::~List(void) {
employeeInfo* currNode = head, *nextNode = NULL;
while (currNode != NULL) {
nextNode = currNode->next;
// destroy the current node
delete currNode;
currNode = nextNode;
}
}
employeeInfo* List::InsertEmployee(string nama,int number,string affiliate) {
int currIndex = 0;
employeeInfo* currNode = head;
employeeInfo* prevNode = NULL;
while (currNode) {
prevNode = currNode;
currNode = currNode->next;
currIndex++;
}
employeeInfo* newNode = new employeeInfo;
newNode->name = nama;
newNode->id=number;
newNode->department= affiliate;
if (currIndex == 0) {
newNode->next = head;
head = newNode;
} else {
newNode->next = prevNode->next;
prevNode->next = newNode;
}
return newNode;
}
void List::DisplayList()
{
int num = 0;
employeeInfo* currNode = head;
cout << "Employee Name :"<<currNode->name <<endl;
cout << "Employee ID :"<<currNode->id<<endl;;
cout << "Age :"<<currNode->department<<endl;
currNode = currNode->next;
}
int main()
{
List test;
test.DisplayList();
getch();
return 0;
}
The "employed" object in the above codeing is a sets of value which i want to initialised with the linklist before i want to insert the new Employee during runtime of the program.