Scheme function to reverse a list

后端 未结 4 1326
甜味超标
甜味超标 2021-01-16 13:36

For my programming languages class I\'m supposed to write a function in Scheme to reverse a list without using the pre-made reverse function. So far what I got was

4条回答
  •  自闭症患者
    2021-01-16 13:46

    Step through the list and keep appending the car of the list to the recursive call.

    (define (reverseList lst)
    (COND
    ((NULL? lst) '())
    (ELSE (APPEND (reverseList(CDR lst)) (LIST (CAR      lst))))
    ))
    

提交回复
热议问题