Sorting a LinkedList
I am having trouble with sorting my linked list can anyone help me and let me know what I am doing wrong?
I need to sort in and put it in a list.
and If you can give me some pointers to print the list at the end with a new method public void print().


        public class SortedLinkedList<T extends Comparable<? super T>>
                 extends LinkedList<T> 
        {
            private LinkedList<T> list;  //the sorted list
    
            //the constructor
            public SortedLinkedList(LinkedList<T> in)
            {
                if(in.isEmpty())
                {
                    System.out.println("Empty list");
                }
                else
                {
                     LinkedList<T> first = new LinkedList<T>(in.subList(0, in.size()/2));
                     LinkedList<T> second = new LinkedList<T>(in.subList(in.size   ()/2,in.size()));
                     LinkedList<T> sortList = new LinkedList<T>();
            
                     int i = 0;
                     int j = 0;
                     while(i<first.size() && j<second.size())
                     {
                         if(first.get(i).equals(second.get(j)) || first.get(i).compareTo(second.get(j))<0)
                         {
                              sortList.add(first.get(i));
                              i++;
                         }
                         else
                         {
                              sortList.add(second.get(j));
                              j++;
                         }
                         if(i == first.size())
                         {
                              for(int k = j; k<second.size(); k++)
                              {
                                  sortList.add(second.get(k));
                              }
                         }
                         else
                         {
                              for(int x = i; x<first.size(); x++)
                              {
                                  sortList.add(first.get(x));
                         }
                    }
               
                }
             }
         }
        }
Sorting a LinkedList
===

I am having trouble with sorting my linked list can anyone help me and let me know what I am doing wrong?
I need to sort in and put it in a list.
and If you can give me some pointers to print the list at the end with a new method public void print().


        public class SortedLinkedList<T extends Comparable<? super T>>
                 extends LinkedList<T> 
        {
            private LinkedList<T> list;  //the sorted list
    
            //the constructor
            public SortedLinkedList(LinkedList<T> in)
            {
                if(in.isEmpty())
                {
                    System.out.println("Empty list");
                }
                else
                {
                     LinkedList<T> first = new LinkedList<T>(in.subList(0, in.size()/2));
                     LinkedList<T> second = new LinkedList<T>(in.subList(in.size   ()/2,in.size()));
                     LinkedList<T> sortList = new LinkedList<T>();
            
                     int i = 0;
                     int j = 0;
                     while(i<first.size() && j<second.size())
                     {
                         if(first.get(i).equals(second.get(j)) || first.get(i).compareTo(second.get(j))<0)
                         {
                              sortList.add(first.get(i));
                              i++;
                         }
                         else
                         {
                              sortList.add(second.get(j));
                              j++;
                         }
                         if(i == first.size())
                         {
                              for(int k = j; k<second.size(); k++)
                              {
                                  sortList.add(second.get(k));
                              }
                         }
                         else
                         {
                              for(int x = i; x<first.size(); x++)
                              {
                                  sortList.add(first.get(x));
                         }
                    }
               
                }
             }
         }
        }