]> 4ch.mooo.com Git - 16.git/commitdiff
working on palllist.c
authorsparky4 <sparky4@cock.li>
Wed, 1 Feb 2017 16:04:22 +0000 (10:04 -0600)
committersparky4 <sparky4@cock.li>
Wed, 1 Feb 2017 16:04:22 +0000 (10:04 -0600)
makefile
src/lib/ll.c [new file with mode: 0755]
src/lib/ll.h [new file with mode: 0755]
src/palllist.c

index c0546833bb25e518570cbbc99d080cd95eb58c01..9cf9bfca4546f75d95a65d0b1fe4b165d06e51e9 100755 (executable)
--- a/makefile
+++ b/makefile
@@ -248,7 +248,7 @@ vrstest.exe:        vrstest.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
 #vgacamm.exe:  vgacamm.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
 palettec.exe:  palettec.$(OBJ) gfx.lib $(DOSLIB)
 palettel.exe:          palettel.$(OBJ) gfx.lib $(DOSLIB)
-palllist.exe:          palllist.$(OBJ) gfx.lib $(DOSLIB)
+palllist.exe:          palllist.$(OBJ) gfx.lib $(DOSLIB) ll.$(OBJ)
 pcxtest2.exe:   pcxtest2.$(OBJ) gfx.lib $(DOSLIB)
 #planrpcx.exe: planrpcx.$(OBJ) gfx.lib
 maptest.exe:   maptest.$(OBJ) 16_map.$(OBJ) 16_head.$(OBJ) gfx.lib $(DOSLIB) $(16LIB)
@@ -352,6 +352,7 @@ vgmSnd.$(OBJ):      $(VGMSNDLIB)/vgmSnd.c $(VGMSNDLIB)/vgmSnd.h
 #memory.$(OBJ):$(EXMMLIB)/memory.c $(EXMMLIB)/memory.h
 c_utils.$(OBJ):$(MODEXLIB)/c_utils.asm
 modex.$(OBJ):   $(MODEXLIB)/modex.asm
+ll.$(OBJ):             $(SRCLIB)/ll.c  $(SRCLIB)/ll.h
 
 #
 #other~
diff --git a/src/lib/ll.c b/src/lib/ll.c
new file mode 100755 (executable)
index 0000000..98b1246
--- /dev/null
@@ -0,0 +1,105 @@
+#include "src/lib/ll.h"\r
+\r
+void print_list(node_t * head)\r
+{\r
+       node_t * current = head;\r
+\r
+       while (current != NULL)\r
+       {\r
+               printf("%d\n", current->val);\r
+               current = current->next;\r
+       }\r
+}\r
+\r
+void pushe(node_t * head, int val)\r
+{\r
+       node_t * current = head;\r
+       while (current->next != NULL)\r
+       {\r
+               current = current->next;\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
+}\r
+\r
+void pushs(node_t ** head, int val)\r
+{\r
+       node_t * new_node;\r
+       new_node = malloc(sizeof(node_t));\r
+\r
+       new_node->val = val;\r
+       new_node->next = *head;\r
+       *head = new_node;\r
+}\r
+\r
+int pop(node_t ** head)\r
+{\r
+       int retval = -1;\r
+       node_t * next_node = NULL;\r
+\r
+       if (*head == NULL) {\r
+               return -1;\r
+       }\r
+\r
+       next_node = (*head)->next;\r
+       retval = (*head)->val;\r
+       free(*head);\r
+       *head = next_node;\r
+\r
+       return retval;\r
+}\r
+\r
+int remove_last(node_t * head)\r
+{\r
+       int retval = 0;\r
+       node_t * current;\r
+\r
+       /* if there is only one item in the list, remove it */\r
+       if (head->next == NULL) {\r
+               retval = head->val;\r
+               free(head);\r
+               return retval;\r
+       }\r
+\r
+       /* get to the last node in the list */\r
+       current = head;\r
+       while (current->next->next != NULL) {\r
+               current = current->next;\r
+       }\r
+\r
+       /* now current points to the last item of the list, so let's remove current->next */\r
+       retval = current->next->val;\r
+       free(current->next);\r
+       current->next = NULL;\r
+       return retval;\r
+\r
+}\r
+\r
+int remove_by_index(node_t ** head, int n)\r
+{\r
+       int i = 0;\r
+       int retval = -1;\r
+       node_t * current = *head;\r
+       node_t * temp_node = NULL;\r
+\r
+       if (n == 0) {\r
+               return pop(head);\r
+       }\r
+\r
+       for (i = 0; i < n-1; i++) {\r
+               if (current->next == NULL) {\r
+                       return -1;\r
+               }\r
+               current = current->next;\r
+       }\r
+\r
+       temp_node = current->next;\r
+       retval = temp_node->val;\r
+       current->next = temp_node->next;\r
+       free(temp_node);\r
+\r
+       return retval;\r
+}\r
diff --git a/src/lib/ll.h b/src/lib/ll.h
new file mode 100755 (executable)
index 0000000..f9b4e5e
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __LL_H__\r
+#define __LL_H__\r
+#include <stdio.h>\r
+#include "src/lib/16_tail.h"\r
+\r
+typedef struct node\r
+{\r
+       struct node     *prev;\r
+       rgb_t   d;\r
+       int val;\r
+       struct node     *next;\r
+} node_t;\r
+\r
+void print_list(node_t * head);\r
+void pushe(node_t * head, int val);\r
+void pushs(node_t ** head, int val);\r
+int pop(node_t ** head);\r
+int remove_last(node_t * head);\r
+int remove_by_index(node_t ** head, int n);\r
+\r
+#endif\r
index 3e8bb2f7df57404aa6939feb49c131ca98ad9501..f6949c1a69db70c84fc916c0102db2b547b64521 100755 (executable)
  * i am going to work on a really big area of code it will be on the refresh system, the walking/scrolling system, things that use showpage, adding disableing 8087 functions if no 8087 detected, and a bunch of other things i cannot remember off the top of my head because i am BURNT. I need a small break~ -- -- -- -- update! i am working on this i made ZC_WALK and i am going to move to VRL/VRS soon! .\r
  * ==== PRE SHOWPAGE TO SHOWMV CONVERSION ==== i am going to work on a really big area of code it will be on the refresh system, the walking/scrolling system, things that use showpage, adding disableing 8087 functions if no 8087 detected, and a bunch of other things i cannot remember off the top of my head because i am BURNT. I need a small break~ -- -- -- -- update! i am working on this i made ZC_WALK and i am going to move to VRL/VRS soon!\r
  */\r
-#include <stdio.h>\r
+#include "src/lib/ll.h"\r
 \r
 void\r
 main(int argc, char *argv[])\r
 {\r
-//TOO TIREDWWWW\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
+\r
+       nx = head;\r
+       for(i=1; i<\r
+               //PAL_SIZE\r
+               5\r
+               ; i++)\r
+       {\r
+               printf("        i=%d\n", i);\r
+               pushe(nx, i);\r
+               nx = nx->next;\r
+       }\r
+       nx->next = NULL;\r
+\r
+       nx = heao;\r
+       for(i=8; i>0; i--)\r
+       {\r
+               printf("        i=%d\n", i);\r
+               pushe(nx, i);\r
+               nx = nx->next;\r
+       }\r
+       nx->next = NULL;\r
+       print_list(head);\r
+       printf("\n");\r
+       print_list(heao);\r
+       free(head);\r
+       free(heao);\r
 }\r