returning true if successful deleting the node c++ : I have an assignment where I have to find the node at the end of the linked list (the one just before the tail) and I have to return it and delete it. if its successful and its deleted then I return true so its basically a bool function. So far I dont know what I am doing wrong and this is what I wrote:

    bool List::getBack(int & key)
    {
        Node *temp = new Node;
        Node *prev = new Node;
        temp = head;
        if(tail=head)
	{
	return false;
	}
	else {
		while (temp->next != nullptr)
		{
			prev = temp;
			temp = temp->next;
		}
		tail = prev;
		prev->next = nullptr;
		delete temp;
		return true;
	}
    }
Thank you very much! I hope I gave a clear question. I do not want anyone solving my question I just need help with understanding because I have been stuck for hours.
