Writing a search method

Hello,
I’m supposed to write a simple method, public void insertInSorted(Node x), that will insert the node into the sorted list in a manner such that the sorted list remains sorted. What is meant by sorted is defined by the compareTo() operator of the type of objects that are inserted in the list. I only want to consider the class Integer which has compareTo() defined in a way that is consistent with the int that each Integer contains.

I have attached the node in reference.

Thanks
Harry

hi,
If you can change ur code then if you u use Set Interface (or TreeSet Object) then it will automatically arrange the elements in sorted order.
If this doent work then also u can implement Comparator interface and overrride int compare(Object,Object) to work according to ur requirement.
The above mentioned classes and interfaces are there in java.util package so for syntax u can refer to javadocs.