Question: LISP PROGRAMMING c. A function called is-sorted that takes one parameter that is a list and returns true (t) or false (nil) based on whether
LISP PROGRAMMING
- c. A function called is-sorted that takes one parameter that is a list and returns true (t) or false (nil) based on whether the list is sorted in ascending order or not. Note that an empty list or a list with a single element are sorted by default. Implementation suggestion: using dolist where you store the previous element in a variable as you go along, or recursion.
Examples of results: (is-sorted '()) ; t (is-sorted '(10)) ; t (is-sorted '(5 5 5)) ; t (is-sorted '(4 3 2 1)) ; nil (is-sorted '(2 5 9 12 14)) ; t
- d. A function called reverse that reverses a list. The function takes one parameter that you can assume to be a list, and returns another list which is the reverse of the argument (you don't need to do the operation in place). You can use the function list that creates a list out of its arguments, or append that concatenates two lists and returns the result. Implementation suggestion: using dolist or recursion.
Examples of results: (reverse '()) ; '() or nil (reverse-list '(2)) ; (20) (reverse-list '(1 2 3)) ; (3 2 1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
