Below is one src demo to reverse one single-linked list:
1 struct listNode {
2 int value;
3 listNode* next;
4 };
5
6 listNode* reverseList(listNode* phead)
7 {
8 listNode* pcur = phead;
9 listNode* pprev = 0, *pnext = 0;
10 while (pcur) {
11 pnext = pcur->next;
12 pcur->next = pprev;
13
14 pprev = pcur;
15 pcur = pnext;
16 }
17 return pcur;
18 }