[Solved] Algorithm for a Recursive function for a ArrayList and when a arrayList is empty return the exact array [closed]


If I understand correctly what you’re asking, something like this should satisfy it, but please note that recursion is not really the best way to achieve what you’re apparently trying to do:

public static void count(ArrayList<Double> list) {
  if (list.empty()) {    
     return; // or consider using if/else
  }

  double total = total(list);

  if (total>100) {
    list.remove(0);
    count(list); // recursive call
  } else if (total<100) {
    list.add(0, 100-total);
  }
}

1

solved Algorithm for a Recursive function for a ArrayList and when a arrayList is empty return the exact array [closed]