We can characterize recursively the operation of deleting all occurrences of an element elem from a list lis as follows:
Recursive implementation:
public static ListNode deleteAll(ListNode lis, String s) { if (lis == null) return null; else if (lis.info.equals(s)) return deleteAll(lis.next, s); else { lis.next = deleteAll(lis.next, s); return lis; } }
Note: It does not make sense to apply the generator node technique when we implement an operation on lists using recursion. Such a technique makes only sense for an iterative implementation, and typically only when the list is modified by the operation.