I have written this piece of code, and I have several questions.
1st. May I use typedef to replace Node*, such as typedef Node* NodePtr; because I had error no matter where I put this, I don understand why.
2nd. This is my code for the constructor, why do I not have to include "Node* HeadList = new Node"????
LinkedList::LinkedList() {
//Node* HeadList = new Node;
HeadList = NULL;
}
3rd. In my insertItem, I have to declare several Nodes, and I don understand why I can't declare them and then assign their value? e.g I have to write "Node* newPtr = new Node", but I can't first write Node* newPtr, then "newPtr = new Node", and further more, why do I have to write "Node* newPtr = new Node" in this case but not for the constructor?
I appreciate for all the repies!!! I really need helps!!
2) You already declared HeadList as a member of the class, therefore you
could just write HeadList = new Node; in the constructor. But writing
Node* HeadList = new Node; is trying to declare a local variable named
HeadList.