How do you delete the tail node of a singly linked list if the
link has
the head and does not have tail? Write the code. How much time
does
it take to Do it?
It takes O(n) as we dont have the tail node so we need to iterate the till before last node and remove that node
void deleteEnd()
{
// need to to find the lst before node
Node prev = head;
// iterate till the last node
while (prev.next.next != null)
prev = prev.next;
// making the prev.next as null so that the link will be removed
prev.next = null;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.