jonas
News Fan!
- Reaction score
- 73
Code:
rec_reverse(last_of_rev,to_rev) = if to_rev != nil:
next_rev = to_rev.next;
to_rev.next = last_of_rev;
rec_reverse(to_rev,next_rev)
reverse(to_rev) = rec_reverse(nil, to_rev)
Code:
reversed list list to be reversed
(|<-()<-...<-() , []->()->...->()->|)
after one recurisve step becomes:
(|<-()<-...<-()<-[] , ()->...->()->|)
at the end of recursion becomes:
(|<-()<-...<-()<-[]<-()<-...<-() , |)
Last edited: