No. There is no such thing as a while-else construct in C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//use this pointer to delete nodes
Node* tempDel = head;
//keep a reference to the next node to delete
//so you don't lose it when you call delete on
//the other pointer
Node* tempNext = nullptr;
tempNext = tempDel->next;
tempDel = tempNext;
I'm assuming that head will be null if the list is empty, so if you pass in an empty list the 'while' block will never execute and you won't attempt to free a null pointer.