public void delete(int x) { Node current = head; Node previous; if (current.getD
ID: 3540657 • Letter: P
Question
public void delete(int x) {
Node current = head;
Node previous;
if (current.getData() == x) {
// case 1 delete the head
head = head.getNext();
} else {
while (current.getData() != x) {
previous = current;
current = current.getNext();
if (current.getData() == x) {
// case 2 delete in the middle or end
previous.setNext(current.getNext());
break;
}// if
}// if else
}// while
System.out.println("Nothing to delete");
}// if else
when you use recursion please use Rec to know which part called itself.
Explanation / Answer
please see here http://pastebin.com/AJUEaaYP
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.