Write a Scheme function reverse that takes as input a list a

Write a Scheme function reverse that takes as input a list and returns a list with the same elements, but in reverse order.

Solution

(define (reverse dataList)
(my-reverse-list dataList \'()))

(define (my-reverse-list dataList acc)
(if (null? dataList)
acc
(reverse-helper (cdr dataList) (cons (car dataList) acc))))

(reverse \'(5 6 7 8 9))
=> \'(9 8 7 6 5)

 Write a Scheme function reverse that takes as input a list and returns a list with the same elements, but in reverse order.Solution(define (reverse dataList) (

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site