|
The best approach, when you're new to linked lists, is to make a short one by hand, using paper and pencil (aid to visualization). Let's presume to want to insert a node. Look at your list, observe which pointers you have to change in order to break a link, point out to a new node, and point back in to the original. Don't just scribble. Erase a link name/destination, write in the new info, and continue to the next step in your procedure. Don't rely on your memory, your program won't be able to -- write something you're going to erase to a scratchpad area. You may find that your procedure needs tuned; you've lost a critical value (null pointer, seg fault, out into the weeds goes your program, barfing on its shoes all the way).
You really haven't written anything significant for us to critique. I'm not going to write it for you. On the other hand, I may actually copy/paste the code you produce, get out compilation errors, point out logical errors, and suggest changes.
Someone might come along and do it for you. Better you do it yourself, with all the help we're prepared to give.
If you have a deadline problem, the odds are very good you brought it on yourself as a fan of procrastination or partying.
|