Q:

Attempt to do recursion in Apex

This simple method I wrote is an attempt to mimic the equivalent iterative method (I'm just curious about recursion in Apex). It must return the element of a list of custom objects that have the older Createddate. 
I printed head and current list value for each recursion layer and the result is correct, but returning to the caller I had a "List out of bounds" error. Since base cases are covered, which further step do I need to do to avoid this error?
Let the size of COset = n, the index in which I got the error is always n-1.
public static customer_Obj__c solveQueueRic(List<customer_Obj__c> COset,Integer index,customer_Obj__c head){
        customer_Obj__c lg = COset[index];
        if(index == 0){
            head = lg;
            return solveQueueRic(COset,index+1,head);
        }
        if(index < COset.size()){
            if(lg.Createddate < COset[index].Createddate){
                head = lg;
            }
            return solveQueueRic(COset,index+1,head);
        }
        return head;
    }

A:

You are getting this error because of this below line
customer_Obj__c lg = COset[index];

Lets say, size of COset is 4 i.e. you can go upto index 3, so when your code goes into recursion and when index reaches 4, it is bound to give you List index out of bound exception as there won't be any element at index 4 as size of your list is 4.
You can instead, move that above line inside your condition something like below
public static customer_Obj__c solveQueueRic(List<customer_Obj__c> COset,Integer index,customer_Obj__c head){
    customer_Obj__c lg;
    if(index == 0){
        lg = COset[index];
        head = lg;
        return solveQueueRic(COset,index+1,head);
    }
    if(index < COset.size()){
        lg = COset[index];
        if(lg.Createddate < COset[index].Createddate){
            head = lg;
        }
        return solveQueueRic(COset,index+1,head);
    }
    return head;
}

