This function would not work as you expect to because you are assigning null to a local pointer. In this function, Last points to the last node. If you assign null to this pointer, it will no longer point to the last node, but null. This has nothing to do to where the previous noue, before this one, points to.
This was the point of the Prev variable in the first iteration of the function. When we finally established that we were at the end of the list, we knew what node was pointing to the last node. In the second iteration, we lose that information, and so we cannot break the ties to the last node as we should be able to.
Just because you assign null to a pointer, it does not mean that every other pointer that points to the same location as that pointer pointed to will become null. You essentially did the following:
Code:
int real = 32;
int * pointer1 = real;
int * pointer2 = real;
pointer 1 = null
Would you expect pointer 2 above to now point to null or 32? It indeed points to 32. Now look back on your code. Pointer1 is Last, while next(Prev) is Pointer2.
I hope this explains the issue well enough. Good Luck!
-Ted