Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class that provides the following three methods: Iteratively reverse a l

ID: 3827458 • Letter: W

Question

Write a class that provides the following three methods: Iteratively reverse a list| public static LListiterativeReverseList(LList list) that accepts a reference to a LList and returns a reference to another LList that contains the data of the original list in reverse order. Your method should be implemented using iteration. Recursively Reverse a list public static LListrecursiveReverseList(LLidt list) that accepts a reference to a LList and returns a reference to another LList that contains the data of the original list in reverse order. Your method should be implemented using recursion. Sort Using ArrayList public ststic ArrayList insertSort(ArrayList list) that accepts a reference to an ArrayLIst and returns another ArrayList that contains the data of the original list in ascending order. You can implement your method as insertion sort or selection sort. You cannot use the Java sort methods. Write the class to tes

Explanation / Answer

//assuming llist<E> data memeber variable as
//data
//and pointing variable is
//next
class LList<E>
{
    E data;
    LList<E> next;

  
    public LList<E> iterativeReverseList(LList<E> list)
    {
   LList<E> temp=list,temp2=null;//temp variables to traverse list
   LList<E> result_head=null;//variable which stores the reverse list
  
   //iteratively traversing list
  
   while(temp!=null)//creating reverse list iteratively....
   {
       result_head=new LList<E>();
                result_head.data=temp.data;
                result_head.next=temp2;
                temp2=result_head;
       temp=temp.next;
   }
      
      
        return result_head;//return reversed list..
      
      
      
      
      
    }
    //recursive method to revers list
  
    public LList<E> recursiveReverseList(LList<E> list)
    {
  
      
        if(list==null)
            return list;
        LList<E> temp;
        temp=recursiveReverseList(list.next);//traversing list recursively
        //returning list..
        LList<E> result_head=new LList<E>();
        result_head.data = list.data;
        result_head.next=temp;
        return result_head;
      
      
      
      
    }
  
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote