summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-06-21 16:43:17 -0600
committermo khan <mo.khan@gmail.com>2020-06-21 16:43:17 -0600
commit4d76691e7809ce90b1d302cc1a14343d0ab30fa0 (patch)
treef4073b94b275a222941c5b02c8c226e8f7dc13ab
parentc53307c2aa6962107d1cb7d4d8ab2d328045f70a (diff)
Collapse declarations closer to usage
-rw-r--r--assignments/01/swap_linked_list_test.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/assignments/01/swap_linked_list_test.c b/assignments/01/swap_linked_list_test.c
index da0b38c..fda3b33 100644
--- a/assignments/01/swap_linked_list_test.c
+++ b/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;
}