viewing paste Reverse LinkedList | C++

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Node* reverse(Node* p){
       
        Node* head = p;
       
        if(p == nullptr) //nullptr requires c++11
                return head;
       
        head = cons(car(p),nullptr);
        p = cdr(p);
       
        while(p != nullptr){
                head = cons(car(p),head);
                p = cdr(p);
        }
       
        return head;
       
}
Viewed 662 times, submitted by Streusel.