Algorithms and Data Structures in an Object-Oriented Framework (“ADSOOF”)

Code for “Lisp Lists and Recursion” section

Note, in the front-end for the code here, in most cases you will be asked to type something in following the prompt “Enter a list of integers” in. What it is expecting here is for the list to be entered in the standard textual representation for Lisp lists. That is, the integers should be separated by commas, and the whole list should have [ at its start and ] at its end. Do not confuse this with what you are asked in other front ends where the prompt is something like “Enter some numbers (all on one line, separated by spaces)”, where you are expected to put spaces between the numbers. The word “list” in the prompt in the front-end code here has the specific meaning of “Lisp list”, it is not just asking for the numbers to be typed with spaces between them.

Although print statements should not be put in code unless they are part of the requirements, it can help to put them in while developing the code for debugging purposes, so long as they are taken out in the final version. It may help you understand recursion better to see some examples with print statements to show you what is happening, so there are some given below.

Code with print statements for illustration

There are version of some of the above methods here with added print statements so you can follow the execution. The print statements will give the values of arguments to method calls, and what is being returned, and in some cases the values of local variables within the calls. After each is printed, you need to type a new line for execution to continue.

Code for recursion with arrayLists


Matthew Huntbach

Last modified: 16 July 2019