Reverse list (C achieved)

Reverse list

Unidirectional linear inversion table linklist

N the list before reversing done it many times, because there are many reverse list approach, the idea is not the same each time, once to spend time thinking think, believe it will error, the list of today's processes look picture , credited a method, a way to do it in the end.

List Reverse(List L){
    List p, q;
    p = L->Next;
    L->Next = NULL;// 先将头链表next指针置空
    // q要始终指向L的next,做为已排好序列的第一个元素
    // p要指向待排序列的第一个元素,p为空则序列全部反转
    while(p){
         q = p; 
         p = q->Next;
         q->Next = L->Next;
         L->Next = q; 
    }
    return L;
}

Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
Map and thinking to understand that time will naturally write

Published 19 original articles · won praise 4 · Views 490

Guess you like

Origin blog.csdn.net/qq_35050438/article/details/103854403