Question: You are to write a Java program name MyLinkedList.java that create/build the LinkedList data Structure that exist in the java library. The class must be

You are to write a Java program name MyLinkedList.java that create/build the LinkedList data Structure that exist in the java library. The class must be written to accept any type of Objects. The following must be implemented i.e. YOU must write the code (do not import them from the Java Library):

  1. One default constructor that will create an empty LinkedList object

public MyLinkedList();

  1. Another constructor that create a LinkedList object with n as head----

public MyLinkedList(Object n);

  1. A method that allows you to place a value at the end of the MyLinkedList ----

public void add(Object x);

  1. A method that allows you to place a value at a given location ----

public void add(int index, Object x);

  1. A method that allows you to retrieve a value from a given location ----

public Object get(int index);

  1. A method that allows you the number of elements in the MyLinkedList ----

public int size();

  1. A method would test to see if the MyLinkedList is empty ----

public boolean isEmpty();

  1. A method that see if a particular object exist in the MyLinkedList t ---

public boolean isIn(Object ob);

  1. A method that will return the location of first occurrence of an Object starting from location 0 -----

public int find (Object n);

  1. A method that will remove the first occurrence of an Object starting from location 0 -----

public void remove (Object n);

Now, write a driver program (the class with the public static void main(String[] args) method) name testLinkedList.java to test the MyLinkedList data structure you just created. That is, you must test all ten (including the default constructor) of the above methods.

-For those that are returning a value, print out the returned value to the screen and

-For those that are not returning a value, print a message that indicate if it successfully completed its task.

-After you test each method, please print the list.

-To test the MyLinkedList, you must randomly generate 15 integer numbers ranging from 1 to 25 and add to the two MyLinkedList you created

2 Given the singly linked list you created above, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place: do not create a new linked list

Example 1:

Input: 1->2->3->4->5->NULL

Output: 1->3->5->2->4->NULL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!