Hello, the 'add' function below seems to be creating nodes accordingly.
However, trying to display node is not working. It crashes when I attempt to hop to next node. Can someone confirm what is wrong?
It looks like your add() method is trying to add a node with data==1 at position n. Is that what it's supposed to do? Usually a method like this adds a node with data=n to the front or the back of the list.
In any case, line 17 points head at the new node, which blows away anything that was already in the list.
Please explain what add() is supposed to do and then we can help you code it correctly.
Hello, Mr lastchance, I did as you suggested and it is still crashing.
dhayden, I am creating the node and adding elements to it. The first element has "1". Then the second element and beyond will receive value data=2, 3 etc.
When I ran the first time, it did not crash either. I am wondering if there is a memory leak somewhere that eventually builds up and end up crashing. I was running for 100 nodes.