Texts: Linked Lists
4. 20 points Given a linked list of integers, write a new method called skipify() that removes nodes with increasing increments. The method must modify the input linked list directly and not print anything on the screen.
For example:
Input linked list: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Result after calling skipify() on linked list: 1, 2, 3, 4, 10
Fill in the blanks below to correctly implement the skipify() method as a new method of the SLinkedList class. Write only one statement per line.
public class Node {
public int data;
public Node next;
}
/** Singly linked list, as defined in the lecture notes. */
public class SLinkedList {
public Node head; // head node of the list
public void skipify() {
Node n = head;
int incr = 1;
while (n != null) {
Node nextNode = null;
for (int i = 0; i < incr; i++) {
if (n.next == null) {
break;
}
nextNode = n.next;
n.next = nextNode.next;
}
n = nextNode;
incr++;
}
}
}