Revers a list

//reverse a list
//this question are frequently asked in interview. hope it can help you.

static void Reverse(struct node** node){ // don't tell me you can't understand the **
//1. declare three pointer
struct node* result = NULL;
struct node* current = *headRef;
struct node* next;

    while (current != NULL) {    
        next = current->next; // tricky: note the next node
        current->next = result; // move the node onto the result
        result = current;
        current = next;
    }
    *headRef = result;
}
posted @ 2007-09-10 15:01  HonestMan  阅读(203)  评论(1编辑  收藏  举报