]> 4ch.mooo.com Git - 16.git/commitdiff
working on palllist.c
authorsparky4 <sparky4@cock.li>
Wed, 1 Feb 2017 16:21:06 +0000 (10:21 -0600)
committersparky4 <sparky4@cock.li>
Wed, 1 Feb 2017 16:21:06 +0000 (10:21 -0600)
src/lib/ll.c
src/lib/ll.h
src/palllist.c

index 98b124681343b2272dcf3d71ad0647334006cdc0..afb69f3f7f045193625226de2cd46dcdb0878c0e 100755 (executable)
@@ -6,7 +6,7 @@ void print_list(node_t * head)
 \r
        while (current != NULL)\r
        {\r
-               printf("%d\n", current->val);\r
+               printf("[%u]    %d\n", current->id, current->val);\r
                current = current->next;\r
        }\r
 }\r
@@ -14,15 +14,21 @@ void print_list(node_t * head)
 void pushe(node_t * head, int val)\r
 {\r
        node_t * current = head;\r
+       current->id = head->id;\r
+       current->next->id = current->id+1;\r
+\r
        while (current->next != NULL)\r
        {\r
+               current->next->id = current->id;\r
                current = current->next;\r
+               current->id++;\r
        }\r
 \r
        // now we can add a new variable\r
        current->next = malloc(sizeof(node_t));\r
        current->next->val = val;\r
        current->next->next = NULL;\r
+       current->next->id++;\r
 }\r
 \r
 void pushs(node_t ** head, int val)\r
index f9b4e5e05986d3572ac98e26e0e0271508276984..f653825ffce1f8b75a3a255ffd2647b2fb748325 100755 (executable)
@@ -9,6 +9,7 @@ typedef struct node
        rgb_t   d;\r
        int val;\r
        struct node     *next;\r
+       word    id;\r
 } node_t;\r
 \r
 void print_list(node_t * head);\r
index f6949c1a69db70c84fc916c0102db2b547b64521..eb428c1d6b9ba81ea78a72755601e29ea6f0828c 100755 (executable)
@@ -64,31 +64,29 @@ main(int argc, char *argv[])
 {\r
        int i;\r
        node_t * head = NULL;           node_t * heao = NULL;\r
-       node_t * nx = NULL;\r
        head = malloc(sizeof(node_t));  heao = malloc(sizeof(node_t));\r
        head->val = 0;                  heao->val = 9;\r
        head->next=NULL;                heao->next=NULL;\r
+       head->id=0;                             heao->id=0;\r
 \r
-       nx = head;\r
        for(i=1; i<\r
                //PAL_SIZE\r
-               5\r
+               7\r
                ; i++)\r
        {\r
-               printf("        i=%d\n", i);\r
-               pushe(nx, i);\r
-               nx = nx->next;\r
+               if(!(i%3)) printf("\n   ");\r
+               printf("%d,", i);\r
+               pushe(head, i);\r
        }\r
-       nx->next = NULL;\r
 \r
-       nx = heao;\r
+       printf("\n");\r
+\r
        for(i=8; i>0; i--)\r
        {\r
-               printf("        i=%d\n", i);\r
-               pushe(nx, i);\r
-               nx = nx->next;\r
+               if(!(i%3)) printf("\n   ");\r
+               printf("%d,", i);\r
+               pushe(heao, i);\r
        }\r
-       nx->next = NULL;\r
        print_list(head);\r
        printf("\n");\r
        print_list(heao);\r