Linked Lists
4. (20 points) Given a linked list of integers, write a new method called
skippify() 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
Result after calling skip() on linked list
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) (1, 3, 6, 10)
(9, 8, 7, 6, 5, 4, 3, 2, 1)
(1, 2, 3, 4)
(9, 7, 4)
(1, 3)
Fill in the blanks below to correctly implement the skippify() 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 skippify() {
Node n = head;
int incr = 1;
while (n != null) {
Node nextNode =
for (int i = 0;
;
if (
break;
nextNode =
} // for loop
} // while loop
} // skippify()
; i++) {