Skip to content

Commit c925b7c

Browse files
committed
Minor code improvements for DataStructure_LinkedList_Reverse
1 parent 8b3d6cc commit c925b7c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

DataStructure/LinkedList/Reverse.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@ PLINKED_LIST
55
Reverse(
66
_In_ PLINKED_LIST LinkedList)
77
{
8-
PLINKED_LIST pPrev, pCurrent, pTemp;
8+
PLINKED_LIST Prev, Current, Next;
99

10-
/* Process the first node */
11-
pPrev = LinkedList;
12-
pCurrent = pPrev->Next;
13-
pPrev->Next = NULL;
10+
/* Preparation for the first node */
11+
Prev = NULL;
12+
Current = LinkedList;
1413

1514
/* Traversal the rest nodes */
16-
while (pCurrent != NULL)
15+
while (Current != NULL)
1716
{
1817
/* Let current node points to the previous node */
19-
pTemp = pCurrent->Next;
20-
pCurrent->Next = pPrev;
18+
Next = Current->Next;
19+
Current->Next = Prev;
2120

2221
/* Move to the next node */
23-
pPrev = pCurrent;
24-
pCurrent = pTemp;
22+
Prev = Current;
23+
Current = Next;
2524
}
2625

2726
/* The last node is the head now */
28-
return pPrev;
27+
return Prev;
2928
}
3029

3130
_Function_class_(FN_EXAMPLE_PROC)
@@ -48,7 +47,7 @@ DataStructure_LinkedList_Reverse(void)
4847
return false;
4948
}
5049

51-
/* Restore LinkedListA and return success */
50+
/* Restore LinkedListA */
5251
LinkedListA = Reverse(ReverseLinkedList);
5352

5453
/* Test LinkedListB, which has only one node */

0 commit comments

Comments
 (0)