Hello there,

Could you please help me with creating this program. I can't see where my error is. The program is meant to sort a list of integers into descending order, if the list is empty return the empty list, otherwise sort the tail and insert the head in the right place. (It must be done using recursion)

Here is what I did but it does not compile.

Code:
import java.util.*;

public class recursion
{
	static genericLists <Integer> L = new genericLists <Integer>();
	
	static  ArrayList <Integer> insertAscending (Integer x, ArrayList <Integer> l)
	{
		
		if (l.size()==0) 
		{
			l.add(0,x);
			return l;
		}
		else 
		{
			if (l.size()==1) 
			{
				int y=l.get(0);
				if (x>y) 
				{
					l.add(0,x);
					l.add(1,y);
					return l;
				}
				else
				{
					l.add(1,x);
					return l;
				}
			}
			else 
			{
				if (x>=l.get(0))
				{
					l.add(0,x);
				}
				else
				{
					ArrayList i = new ArrayList <Integer>();
					for (int j=1; j<l.size();j++)i.add(j-1,l.get(j));
					insertAscending(x,i);
					i.add(0,l.get(0));
					return i;
				}		
			}
		}
	}

	static ArrayList <Integer> sortAscending (ArrayList <Integer> l)
	{
		if(l.isEmpty())
			return l;
	
		else return insertAscending((L.head(l)),sortAscending((L.tail(l))));
	}
	
	public static void main(String [] args)
	{ 	
		System.out.println((maker.makeR(Integer.parseInt(args[0]))));	
		System.out.println(sortAscending(maker.makeR(Integer.parseInt(args[0]))));	
	}
}
These are the two other classes linked with the above recursion.class they work fine. (the problem is with the above code)

"maker" class

Code:
import java.util.ArrayList;
public class maker
{
	static genericLists <Integer> L = new genericLists <Integer>();
	
	static ArrayList  <Integer> makeR (int n)
	{
		if (n==0) return L.cons(0,L.nil());
		else return L.cons(n,makeR(n-1));
	}

	public static void main(String [] args)
	{
		System.out.println(makeR(Integer.parseInt(args[0])));
	}

}
"genericLists" class

Code:
import java.util.*;
public class genericLists  <T>
{
	public  T head (ArrayList  <T> m)
	{
			return m.get(0);
	}
	
	public  ArrayList <T>  tail (ArrayList <T>  t)
	{	
		ArrayList <T> m= new ArrayList <T> (t);
		m.remove(0);	
		return m;
	}
	
	public  ArrayList <T>  nil ()
	{
			return new ArrayList <T>();
	}
	
	public  ArrayList  <T> cons (T t, ArrayList <T> m)
	{	
		ArrayList <T> k= new ArrayList <T>();
		k.add(t);
		k.addAll(m);
		return k;
	}
	
	public  ArrayList <T> append (ArrayList <T>  t, ArrayList <T>  u)
	{	
		if (t.isEmpty()) return u;
		else return cons(head(t),append(tail(t),u));
	}

	public 	 ArrayList <T> reverse (ArrayList <T>  t)
	{	
		if  (t.isEmpty()) return t;
		else return append(reverse(tail(t)),cons(head(t),new ArrayList <T>()));
	}
}
Any help is appreciated. Thank you for your time.