Suppose you have a linked list class that includes BOTH a first and a last point
ID: 3660620 • Letter: S
Question
Suppose you have a linked list class that includes BOTH a first and a last pointer. first points to the first node; last points to the last node. If the list has no nodes, then both first and last are null. Write a instance method, removeFirst(), for this linked list class that removes the first node on the list and updates first and last appropriately. It should return the reference pointer to the removed node. If the list has no nodes when removeFirst is called, your method should return null. please explain, I am new in programming! thanksExplanation / Answer
public Node removeFirst()
{
if (first == null)
{
return null;
}
Node removed = this.first;
if (this.first == this.last)
{
first = null;
last = null;
}
else
{
first = first.next;
}
return removed;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.