Destructively reverse every cons node in an s-expression

136 Views Asked by At

Any ideas how to go about this? I am trying to not create any new nodes.

2

There are 2 best solutions below

1
On

Call nreverse.

0
On

Draw a standard cons-cell diagram of what a list with 5 elements or so looks like. That should give you a big clue right there.

Don't forget to keep a reference to the last cell in the list, which will be your new list head when done.