Reference no: EM133369141
Question: Given is the IntNode class that represents an element in a linked list, and the IntList class that represents a linked list (at the end of the question).
Add a method signed to the IntList class:
public void createList(int[] a, int num)
The method will receive as a parameter an array of numbers and the number num, and will create a list from its members so that all the members in the array that are smaller than or equal to num will be at the beginning of the list, and all the members that are greater than num will be at the end of the list.
For example, if the array was {4, 2, 7, 5, 3, 8, 1} and num = 3 the list that would be created would be:
head 2 3 1 4 7 5 8 null
In this case, the numbers 1, 2, 3 are less than or equal to 3 and therefore appear at the beginning of the list, and the other numbers appear later. The internal order of the numbers in each part is not important.
Defining the departments for the question:
public class IntNode {
private int num;
private IntNode next;
public IntNode(int num, IntNode next) {
this.num = num;
this.next = next;
}
public int getNum() { return num; }
public void setNum(int num) { this.num = num; }
public IntNode getNext() { return next; }
public void setNext(IntNode next) { this.next = next; }
}
public class IntList {
private IntNode head;
public IntList() { head = null; }
}