Write a program that will involve classes, the node class, the linked list class and the main program that instantiates, uses, sorts, and tests an array.
The node class will be used to create each individual node as it is added to the list. It should contain no more than attributes for the data and the fore- and back-links and necessary methods for setting and retrieving the data value.
a. public node(int v) -class constructor, v=data value
b. public node() - class constructor
c. public int get() - returns the data value from the node
d. public void set(int v) -saves the data value v in the node
The linked list class will define the array-like interface between the main program and the linked list array implementation. It has to be coded by you, and not be the built-in Java implementation. It will provide for creation of the head and tail nodes and initialization of them. It will also maintain an integer value containing the current number of nodes in the array. A second integer value will contain the index of the most-recently addressed node and a node reference value will refer to the mod-recently addressed node itself.
a. public BetterArray(int n) -class constructor, n is the initial allocation(the starting array size)
b. public BetterArray() - class constructor, use a default initial allocation
c. public int get(int index) -uses the index to access a specific array element(node) and returns the value to the caller
d. public void put(int value, int index) - uses the index to find the specific array element(node) and saves the data value in the node. If the requested node is outside the current size of the array(linked-list), expand the list to accommodate the new element.
e. public void insert(int value, int index) - uses the index to find the specific array element(node) and saves the data value in the preceding node. If the requested node is outside the current size of the array(linked-list), expand the list to accommodate the new element.
f. public void delete(int index) -uses the index to find the specific array element (node) and deletes it from the list.
The main class will create an object of the BetterArray class and run it through some tests.
a. Create the object and make its size 10 elements.
b. Store the numbers 200 through 209 in the array.
c. Read back the elements with the index values 0 through 19 and display the values.
d. Store the numbers 300 through 319 into the array.
e. Read back the elements with the index values 0 through 19 and display the values.
f. Insert the number 999 immediately before element 14.
g. Read back the elements 0 through 20 and display the values.
h. Delete element 15.
i. Read back the elements 0 through 19 and display the values.
j. Create another object and make its size 1000 elements.
k. Fill it with randomly-generated integers (values between 0 and 1,000,000)
l. Sort the array in either increasing or decreasing order.
m. The program will test the result by comparing each element of the sorted array to the one adjacent to it and reporting any out-of-order results.