Computer Science Consider the code from the DeleteLast() method which removes the last element in a linked list (while also maintaining a tail pointer). public String DeleteLast() { if (head == null) return null; else if (head == tail) { String tempCargo = head.Cargo; head = null; tail = null; return tempCargo; } else { Node temp = head; while (temp.next != tail) { temp = temp.next; } String tempCargo = temp.next.Cargo; temp.next = null; tail = temp; return tempCargo; } } The code can be changed to be recursive by using a recursive method to perform the part of the code that iterates over the list: public String DeleteLastHelper() { if (head == null) return null; else if (head == tail) { String tempCargo = head.Cargo; head = null; tail = null; return tempCargo; } else return DeleteLastRecursive(head); } Q: Write the recursive DeleteLastRecursive method. Test your solution to make sure it performs the same as the iterative version. In C#
Computer Science
Consider the code from the DeleteLast() method which removes the last element in a linked list (while also maintaining a tail pointer).
public String DeleteLast()
{
if (head == null) return null;
else if (head == tail)
{
String tempCargo = head.Cargo;
head = null;
tail = null;
return tempCargo;
}
else
{
Node temp = head;
while (temp.next != tail)
{
temp = temp.next;
}
String tempCargo = temp.next.Cargo;
temp.next = null;
tail = temp;
return tempCargo;
}
}
The code can be changed to be recursive by using a recursive method to perform the part of the code that iterates over the list:
public String DeleteLastHelper()
{
if (head == null) return null;
else if (head == tail)
{
String tempCargo = head.Cargo;
head = null;
tail = null;
return tempCargo;
}
else return DeleteLastRecursive(head);
}
Q: Write the recursive DeleteLastRecursive method. Test your solution to make sure it performs the same as the iterative version. In C#
Step by step
Solved in 3 steps with 1 images