hi everyone!
can someone help me with this program?
I have to make a linked list by reading a file. I have to read the command from the file and make an if else structure. If the command is "add"(this is the part I am having problems) I have to call a function that reads data in the file and adds those to the linked list. the "addOne" function is the one where the problem generates. Can you guys tell me what I am doing wrong?
This is the code:
Is it just the addOne() you are having trouble with?
The local variable last serves no purpose. You could eliminate it.
This line:newNode -> link = newNode; points newNode to itself, creating a closed list with one node.
Are you trying to add a new node to the front of the list here?
If so, the following should work:
1 2 3 4
nodeType *newNode = new nodeType;
newNode->info = newItem;
newNode->link = first;// good for ALL cases
first = newNode;