Give me more powerful algorithm to delete a node from the end of linked list…
First of all, please don’t post pictures of code - just cut and paste and mark it up as code.
Secondly, what language is this?
Thirdly, what do you mean by “more powerful algorithm”? What is wrong with this? You have an O(n) time and O(1) space solution here. Unless it is a bidirectional LL with a pointer to the end, I don’t see how you’re going to do better.
Lastly, this really isn’t a site where people demand solutions. This is a learning site so more commonly people would post their attempts and get help.
Ok! I’ll remember all your points next time! Thank you
This looks like the standard function to pop or dequeue a linked list in C++. If your list structure doesn’t have a
tail, then that’s as efficient as it’s going to get.
You won’t improve the algorithmic complexity here. But if this is C or vanilla C++ (as it appears), you can certainly improve the code. Absent garbage collection, the memory occupied by the deleted node is leaked.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.