6-1 single chain reversal (20 minutes)

Topic Address: https://pintia.cn/problem-sets/15/problems/724

Reverse list, the original list of nodes directly reversed, this is not to create a new list, note empty list requires special sentence

List Reverse(List L) {
    List p, q;
    p = L;
    if(p) q = L->Next;
    else q = NULL;
    while(q) {
        List tmp = q->Next;
        q->Next = p;
        p = q;
        q = tmp;
    }
    if(L) L->Next = NULL;
    return p;
}
View Code

 

Guess you like

Origin www.cnblogs.com/mile-star/p/11455049.html