posted 21 years ago
If you're referring to a singly-linked list to which you have access to the head node reference, just iterate through the list from the head (the first node) until one node before the tail (the last node), then set the link of that node to null. You may also want to set the tail reference to that second to last node as well.
To iterate you'll perhaps create a cursor reference (of the node type) which you'll start at the head and keep moving through the list. You'll know that the cursor is one before the tail when the cursor's link points to the tail (cursor.link == tail). If a tail reference is not being maintained, then you'll know that the cursor is one before the last node when the link of the link of the cursor points to null (cursor.link.link == null).
Realize that if there are only one or two nodes in the list, then exactly the same logic as described above may not work properly. Hopefully you can figure out how to handle such special circumstances.
Good Luck.