Mar 8, 2018 at 11:12pm UTC
I am trying to create a linked list for an assignment. I decided to create 2 header files, one for the class LinkedList and one for the struct.I also have one test cpp and the class cpp.
I can't find the correct way to do it and what I can come up with has a problem. Here is my code:
Node.h
--------------
#ifndef NODE_H
#define NODE_H
struct node {
int value;
node* next;
node* prev;
node(int val, node* pNext, node* pPrev) : value(value), next(pNext), prev(pPrev) {}
};
#endif
LinkedList.h
-------------------
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include "node.h"
class LinkedList {
private:
node *head, *tail, *dummy;
public:
LinkedList();
node* makeDummy();
};
#endif
LinkedList.cpp
---------------
#include "node.h"
#include "LinkedList.h"
#include <iostream>
using namespace std;
LinkedList::LinkedList()
{
head = NULL;
tail = NULL;
dummy = NULL;
}
node* makeDummy() {
int value = INT_MIN;
node* p1 = nullptr;
node* p2 = nullptr;
node* q = new node{value,p1,p2};
return q;
}
testLinkedListcpp.cpp
------------------------
#include "LinkedList.h"
#include "node.h"
#include <iostream>
using namespace std;
int main() {
LinkedList linked;
node* dummy = nullptr;
dummy = linked.makeDummy();
cin.ignore(2);
return 0;
}
If someone could explain me what I am doing wrong, or point me on the right direction it would be awesome.
Thanks