Deep reverse

Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements reversed and with all sublists deep-reversed as well. For example,

(define x (list (list 1 2) (list 3 4)))

x
((1 2) (3 4))

(reverse x)
((3 4) (1 2))

(deep-reverse x)
((4 3) (2 1))

    # Alikhan Askarov
    3 years ago

    не так сложно как кажется

    # Leenday
    9 months ago

    Решение не со всеми случаями списков работает корректно. Например: (define a (list (list 1 (list 1 2)) (list 3 (list 3 4)) (list 5 6)))

    Вернет: 1 ]=> (deep-reverse a) ;Value 16: ((6 5) ((3 4) 3) ((1 2) 1))

Authentication required

You must log in to post a comment.

Login