2.18

练习 2.18 请定义出过程 reverse,它以一个表为参数,返回的表中所包含的元素与参数表相同,但排列顺序与参数表相反:

(reverse (list 1 4 9 16 25))
(25 16 9 4 1)

 
(define (append list1 list2)
  (if (null? list1)
      list2
      (cons (car list1) (append (cdr list1) list2)))
  )
(define (reverse lst) 
  (if (null? (cdr lst))
      lst
      (append (reverse (cdr lst)) (list (car lst)))))
(reverse (list 1 4 9 16 25))
x
 
(25 16 9 4 1)

results matching ""

    No results matching ""