I'm currently working on a project about Linked Lists for my Data Structures class and I'm having a bit of trouble implementing an add method to the Linked List class. Currently, my class definition for the project are as such:
template <class Process>
class LinkedList {
Process _info;
LinkedList* _next;
public:
// Methods
};
class Process {
protected:
int memory_request;
public:
// Methods
};
The Project is to create a Linked List with the List having Process class objects. The add method I am having trouble with is as followed:
template <class Process>
void LinkedList<Process>::add_process(const Process& process) {
if (_info == NULL) {
_info = process;
}
else {
LinkedList<Process>* newList = new LinkedList<Process>(_info, _next);
if (newList == NULL); // throw error TODO
_info = process;
_next = newList;
}
}
When I insert some test data in the main method and run the program, it seems to create the last two items with the last in the list connected to a null Linked List object. I believe I'm doing this correctly, but I need some help figuring out the issue of where its going wrong.
Thanks