11. deep-reverse Define a function similar to the built-in reverse function, except that it acts recursively, reversing the order the members of any nested sublists. You may not use the built-in reverse function as a helper function. However, you may use your own my-reverse function as a helper function. Input: A single list which may contain an arbitrary number of elements and sublists, each sublists may also contain an arbitrary number of elements and sublists, nested to an any depth. Output: A new list which contains all elements in reverse order, as well as recursively reverse order all members of sublists.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
icon
Related questions
Question
100%
11. deep-reverse
Define a function similar to the built-in reverse function, except that it acts recursively, reversing
the order the members of any nested sublists. You may not use the built-in reverse function as a
helper function. However, you may use your own my-reverse function as a helper function.
Input: A single list which may contain an arbitrary number of elements and sublists, each
sublists may also contain an arbitrary number of elements and sublists, nested to an any depth.
Output: A new list which contains all elements in reverse order, as well as recursively reverse
order all members of sublists.
Example:
> (deep-reverse (((4 3) 6) ((7 2 9) (5 1))))
'(((15) (9 2 7)) (6 (34)))
> (deep-reverse ((1 2) 3))
(3 (21))
> (deep-reverse '((4 5)))
'((5 4))
> (deep-reverse (3 6 9 12))
(12 963)
Transcribed Image Text:11. deep-reverse Define a function similar to the built-in reverse function, except that it acts recursively, reversing the order the members of any nested sublists. You may not use the built-in reverse function as a helper function. However, you may use your own my-reverse function as a helper function. Input: A single list which may contain an arbitrary number of elements and sublists, each sublists may also contain an arbitrary number of elements and sublists, nested to an any depth. Output: A new list which contains all elements in reverse order, as well as recursively reverse order all members of sublists. Example: > (deep-reverse (((4 3) 6) ((7 2 9) (5 1)))) '(((15) (9 2 7)) (6 (34))) > (deep-reverse ((1 2) 3)) (3 (21)) > (deep-reverse '((4 5))) '((5 4)) > (deep-reverse (3 6 9 12)) (12 963)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning