From 3274c29216a03baeac8668301301b41257fc2fd2 Mon Sep 17 00:00:00 2001 From: sparky4 Date: Wed, 1 Feb 2017 10:04:22 -0600 Subject: [PATCH] working on palllist.c --- makefile | 3 +- src/lib/ll.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/ll.h | 21 ++++++++++ src/palllist.c | 35 ++++++++++++++++- 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100755 src/lib/ll.c create mode 100755 src/lib/ll.h diff --git a/makefile b/makefile index c0546833..9cf9bfca 100755 --- 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 index 00000000..98b12468 --- /dev/null +++ b/src/lib/ll.c @@ -0,0 +1,105 @@ +#include "src/lib/ll.h" + +void print_list(node_t * head) +{ + node_t * current = head; + + while (current != NULL) + { + printf("%d\n", current->val); + current = current->next; + } +} + +void pushe(node_t * head, int val) +{ + node_t * current = head; + while (current->next != NULL) + { + current = current->next; + } + + // now we can add a new variable + current->next = malloc(sizeof(node_t)); + current->next->val = val; + current->next->next = NULL; +} + +void pushs(node_t ** head, int val) +{ + node_t * new_node; + new_node = malloc(sizeof(node_t)); + + new_node->val = val; + new_node->next = *head; + *head = new_node; +} + +int pop(node_t ** head) +{ + int retval = -1; + node_t * next_node = NULL; + + if (*head == NULL) { + return -1; + } + + next_node = (*head)->next; + retval = (*head)->val; + free(*head); + *head = next_node; + + return retval; +} + +int remove_last(node_t * head) +{ + int retval = 0; + node_t * current; + + /* if there is only one item in the list, remove it */ + if (head->next == NULL) { + retval = head->val; + free(head); + return retval; + } + + /* get to the last node in the list */ + current = head; + while (current->next->next != NULL) { + current = current->next; + } + + /* now current points to the last item of the list, so let's remove current->next */ + retval = current->next->val; + free(current->next); + current->next = NULL; + return retval; + +} + +int remove_by_index(node_t ** head, int n) +{ + int i = 0; + int retval = -1; + node_t * current = *head; + node_t * temp_node = NULL; + + if (n == 0) { + return pop(head); + } + + for (i = 0; i < n-1; i++) { + if (current->next == NULL) { + return -1; + } + current = current->next; + } + + temp_node = current->next; + retval = temp_node->val; + current->next = temp_node->next; + free(temp_node); + + return retval; +} diff --git a/src/lib/ll.h b/src/lib/ll.h new file mode 100755 index 00000000..f9b4e5e0 --- /dev/null +++ b/src/lib/ll.h @@ -0,0 +1,21 @@ +#ifndef __LL_H__ +#define __LL_H__ +#include +#include "src/lib/16_tail.h" + +typedef struct node +{ + struct node *prev; + rgb_t d; + int val; + struct node *next; +} node_t; + +void print_list(node_t * head); +void pushe(node_t * head, int val); +void pushs(node_t ** head, int val); +int pop(node_t ** head); +int remove_last(node_t * head); +int remove_by_index(node_t ** head, int n); + +#endif diff --git a/src/palllist.c b/src/palllist.c index 3e8bb2f7..f6949c1a 100755 --- a/src/palllist.c +++ b/src/palllist.c @@ -57,10 +57,41 @@ * 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! . * ==== 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! */ -#include +#include "src/lib/ll.h" void main(int argc, char *argv[]) { -//TOO TIREDWWWW + 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; + + nx = head; + for(i=1; i< + //PAL_SIZE + 5 + ; i++) + { + printf(" i=%d\n", i); + pushe(nx, i); + nx = nx->next; + } + nx->next = NULL; + + nx = heao; + for(i=8; i>0; i--) + { + printf(" i=%d\n", i); + pushe(nx, i); + nx = nx->next; + } + nx->next = NULL; + print_list(head); + printf("\n"); + print_list(heao); + free(head); + free(heao); } -- 2.39.5