1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | List mergeReverse2(List list1, List list2, List soFar) { if(list1 == null && list2 == null) { return soFar; } List following; if(list1 == null || list1.dato > list2.dato) { following = list2.next; list2.next = soFar; return mergeReverse2(list1, following, list2); } if(list2 == null || list1.dato <= list2.dato) { following = list1.next; list1.next = soFar; return mergeReverse2(following, list2, list1); } return null; } |
Other entries:
- isPrime: Naive version
- isPrime, Optimization 1: Iterate only until the square root of the number
- isPrime, Optimization 2: Only divide by odd numbers, until the square root of the number
- isPrime, Optimization 3: Skip the divisors that are multiple of 2 or 3
- Keep the previosly generated primes and use them to test the following numbers.
- isPrime, Recursive.
No comments:
Post a Comment