template <typename T>
void LinkedList<T>::insertFirst(T data)
{
//Get a linkednode pointer to the first node
LinkedNode<T>* N = 0;
N = new LinkedNode<T>;
N->data = data;
//Get a pointer to this linked lists first linked node
LinkedNode<T>* C = this->mFirst;
//get the new node to point to the first one in the list
if(C->next==0)
{
N->next = 0;
N->prev = 0;
mFirst = N;
mLast = N;
}
else
{
N->next = C;
N->next->prev = N;
N->prev = 0;
mFirst = N; //Only mFirst changes, mLast does not change
}
int main()
{
LinkedList<float> apple;
apple.setData();
apple.printNode();
return 0;
}
]
The code is running but there is some logical problem. It stops after you enter your first data. I am not sure what is wrong if anyone could help that would be greatly appreciated.
Sounds like it's crashing. When dealing with pointers, this most likely means you're dereferencing a null or invalid pointer.
I cannot stress this enough: Use a proper debugger. A debugger allows you to step through your code, line by line, and examine the current state of every value in your program. You'll be so happy once you figure out how to do this.