Commit 4d76691

mo khan <mo.khan@gmail.com>
2020-06-21 22:43:17
Collapse declarations closer to usage
1 parent c53307c
Changed files (1)
assignments/01/swap_linked_list_test.c
@@ -66,30 +66,28 @@ static int size(Node *head) {
 }
 
 void swap(Node **head, int x, int y) {
-  Node *xp, *yp, *xc, *yc, *tmp;
   int count = size(*head);
 
   if (x == y) return;
   if (x >= count) return;
   if (y >= count) return;
 
-  xp = get(*head, x - 1);
-  yp = get(*head, y - 1);
-  xc = get(*head, x);
-  yc = get(*head, y);
+  Node *xp = get(*head, x - 1);
+  Node *yp = get(*head, y - 1);
+  Node *xc = get(*head, x);
+  Node *yc = get(*head, y);
 
-  if (x == 0) {
+  if (x == 0)
     *head = yc;
-  } else {
+  else
     xp->next = yc;
-  }
-  if (y == 0) {
+
+  if (y == 0)
     *head = xc;
-  } else {
+  else
     yp->next = xc;
-  }
 
-  tmp = yc->next;
+  Node *tmp = yc->next;
   yc->next = xc->next;
   xc->next = tmp;
 }