From: sparky4 Date: Wed, 1 Feb 2017 16:21:06 +0000 (-0600) Subject: working on palllist.c X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=8b8c7b996b77654c80d44beaf04f47505cb7b2a9;p=16.git working on palllist.c --- diff --git a/src/lib/ll.c b/src/lib/ll.c index 98b12468..afb69f3f 100755 --- a/src/lib/ll.c +++ b/src/lib/ll.c @@ -6,7 +6,7 @@ void print_list(node_t * head) while (current != NULL) { - printf("%d\n", current->val); + printf("[%u] %d\n", current->id, current->val); current = current->next; } } @@ -14,15 +14,21 @@ void print_list(node_t * head) void pushe(node_t * head, int val) { node_t * current = head; + current->id = head->id; + current->next->id = current->id+1; + while (current->next != NULL) { + current->next->id = current->id; current = current->next; + current->id++; } // now we can add a new variable current->next = malloc(sizeof(node_t)); current->next->val = val; current->next->next = NULL; + current->next->id++; } void pushs(node_t ** head, int val) diff --git a/src/lib/ll.h b/src/lib/ll.h index f9b4e5e0..f653825f 100755 --- a/src/lib/ll.h +++ b/src/lib/ll.h @@ -9,6 +9,7 @@ typedef struct node rgb_t d; int val; struct node *next; + word id; } node_t; void print_list(node_t * head); diff --git a/src/palllist.c b/src/palllist.c index f6949c1a..eb428c1d 100755 --- a/src/palllist.c +++ b/src/palllist.c @@ -64,31 +64,29 @@ main(int argc, char *argv[]) { int i; node_t * head = NULL; node_t * heao = NULL; - node_t * nx = NULL; head = malloc(sizeof(node_t)); heao = malloc(sizeof(node_t)); head->val = 0; heao->val = 9; head->next=NULL; heao->next=NULL; + head->id=0; heao->id=0; - nx = head; for(i=1; i< //PAL_SIZE - 5 + 7 ; i++) { - printf(" i=%d\n", i); - pushe(nx, i); - nx = nx->next; + if(!(i%3)) printf("\n "); + printf("%d,", i); + pushe(head, i); } - nx->next = NULL; - nx = heao; + printf("\n"); + for(i=8; i>0; i--) { - printf(" i=%d\n", i); - pushe(nx, i); - nx = nx->next; + if(!(i%3)) printf("\n "); + printf("%d,", i); + pushe(heao, i); } - nx->next = NULL; print_list(head); printf("\n"); print_list(heao);