Question: Hi, can you answer this question please. Suppose that we are creating a simple ordered list. Ordered list is a Linked list which always adds

Hi, can you answer this question please.

Hi, can you answer this question please. Suppose
Suppose that we are creating a simple ordered list. Ordered list is a Linked list which always adds the element in an increasing order. In the following MyOrderedList class, your task is to create only two methods: add(int v) to add the given element v in the list in a sorted manner. display() to print out all the elements. Note that you are not allowed to make any changes to the Node class and you are not allowed to import anything in your program to answer this question. class Node{ public int value;) public Node next; public Node(int value, Node next) { this. value = value; this. next = next; public class MyOrderedList{) // define a method: public void add(int v) // define a method: public void display() public static void main(String args){ MyOrderedList list = new MyOrderedList();) list. add(20); list . add(40); list. add(10);) System. out. print("List contains: "); List. display(); list. add(50); list. add(30); ) System. out. print("\ list contains: "); list. display(); list. add(5); list. add(35); System. out. print("\ List contains: "); List. display() ; System. out . println(); Your program should work with the above code to produce the following output: [user@sahara ~]$ java MyOrderedList List contains: 10 20 40 List contains: 10 20 30 40 50 List contains: 5 10 20 30 35 40 50

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 Programming Questions!