The conditions for the question

1. you dont have any head ptr
2. you cant traverse as you dont have head ptr
3. its a singly link list
4. each node is dynamically allocated


You only have a pointer to the node which you have to delete, and that is pointing to the last node of the singly link list.


Is it at all possible ?

Recommended Answers

All 3 Replies

Of course. Delete the node you are pointing to.

The question doesn't say you need to clean up the next-pointer in the previous node, which you can't do, but too bad. Stupid requirements cause problems.

so the sanity of the list wont be maintained ? in this case

so the sanity of the list wont be maintained ? in this case

No. The list will become insane (MWAHAHAAAAA) because the new 'last node' will point to the non-existent node you just deleted. You are not given the ability to fix this based on your requirements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.