seems to work

This commit is contained in:
ldlda committed 2024-10-23 22:40:17 +07:00
1 parent 8aa73bde5e
commit 2930b7217d
9 files changed
+280 -105

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "arraylist.h"
int CAPACITY = 24, ADDITIONAL = 16; //id rather just <<=1
int CAPACITY = 24, ADDITIONAL = 16; // id rather just <<=1
// stack list
void ldalistinit(ldaArrayList *l)
+2 -2
View File
@@ -8,12 +8,12 @@ typedef struct LdaArrayList
{
int size;
int capacity; // size big then capacity big 2
int* list;
int *list;
} ldaArrayList;
void ldalistinit(ldaArrayList *l);
int ldalistlen(ldaArrayList *l);
int ldalistcheck(ldaArrayList *l);
// int ldalistcheck(ldaArrayList *l);
int ldalistpush(ldaArrayList *l, int value);
int ldalistadd(ldaArrayList *l, int at, int value);
int ldalistpop(ldaArrayList *l, int *put_here);
+65 -61
View File
@@ -5,6 +5,8 @@
// BE INCREDIBLY FR WITH NODEPTR
// am i doing it right
#define elif else if
// removehidden
dllda *initlda()
@@ -90,8 +92,9 @@ int structure_fixups(dllda *l)
start = start->prev;
count++;
}
if (count > 1)
l->start = start;
l->start = start;
if (count == 1)
l->end = l->start->next;
l->size = count;
return 2;
}
@@ -166,8 +169,6 @@ void dllda_push(dllda *c, uintptr_t ptr)
c->size++;
}
// TODO!
int dllda_len(dllda *c) { return c->size; }
nodeld *adll_find(dllda *l, int i)
@@ -203,25 +204,18 @@ int dllda_rem(dllda *l, int pos, uintptr_t *puthere)
adll_remove(l, c);
return 0;
}
int adll_findHandler(dllda *l, int i, nodeld *c)
int dllda_query(dllda *l, int i, uintptr_t *copy_here)
{
c = adll_find(l, i);
if (c == NULL)
{ // start now is No Longer Null
nodeld *g = adll_find(l, i);
if (g == NULL)
{
if (dllda_len(l) == 0)
return -1;
else
return -2;
};
return 0;
}
int dllda_query(dllda *l, int i, uintptr_t *copy_here)
{
nodeld *g = NULL;
int c = adll_findHandler(l, i, g); // ma
if (c != 0)
return c;
// printf("%p, %p", g, &g);
*copy_here = g->ptr;
return 0;
}
@@ -245,17 +239,18 @@ int dllda_pop(dllda *l, uintptr_t *puthere)
nodeld *endMayBeNull = adll_find(l, dllda_len(l) - 1);
if (endMayBeNull == NULL)
{
if (dllda_len(l) == 0)
return -1;
else
return -2;
int len = dllda_len(l);
if (len == 1)
return dllda_popleft(l, puthere);
elif (len == 0) return -1;
else return -2;
};
*puthere = endMayBeNull->ptr;
adll_remove(l, endMayBeNull);
return 0;
}
// no add to size, also bugs when edges (i mean this is a interceptor)
int adll_intercept(nodeld *tobeplaced, uintptr_t ptr)
int adll_insert(nodeld *tobeplaced, uintptr_t ptr)
{
nodeld *next = tobeplaced;
nodeld *prev = next->prev;
@@ -263,7 +258,10 @@ int adll_intercept(nodeld *tobeplaced, uintptr_t ptr)
new->prev = prev;
new->next = next;
if (prev->next != next || next->prev != prev)
{
free(new);
return -1;
}
prev->next = new;
next->prev = new;
return 0;
@@ -277,12 +275,12 @@ int dllda_insert(dllda *l, int pos, uintptr_t ptr)
nodeld *replaced = adll_find(l, pos);
if (replaced == NULL)
return -1;
if (adll_intercept(replaced, ptr) != 0)
if (adll_insert(replaced, ptr) != 0)
return -1;
l->size++;
return 0;
}
else if (pos == len)
else if (pos == len) // funny you can do that
dllda_push(l, ptr);
else if (pos == 0)
dllda_pushleft(l, ptr);
@@ -350,42 +348,48 @@ int dllda_to_list(dllda *l, uintptr_t *arr)
return len;
}
// int main(int argc, char const *argv[])
// {
// dllda *new = initlda();
// int dsa = 17;
// dllda_push(new, (uintptr_t)&dsa);
// // traverse(new);
// int item1 = 1;
// dllda_push(new, (uintptr_t)&item1);
// // traverse(new);
int _main(int argc, char const *argv[])
{
dllda *new = initlda();
int dsa = 17;
dllda_push(new, (uintptr_t)&dsa);
// traverse(new);
printItOut(new);
int item4 = -2;
dllda_pushleft(new, (uintptr_t)&item4);
printItOut(new);
// traverse(new);
int item1 = 1;
dllda_pushleft(new, (uintptr_t)&item1);
// traverse(new);
printItOut(new);
int item5 = 9;
dllda_insert(new, 2, (uintptr_t)&item5);
printItOut(new);
// traverse(new);
// int item2 = 4;
// dllda_push(new, (uintptr_t)&item2);
// // traverse(new);
// int item3 = 13;
// dllda_push(new, (uintptr_t)&item3);
// // traverse(new);
// int item4 = -2;
// dllda_pushleft(new, (uintptr_t)&item4);
// int item5 = 9;
// dllda_insert(new, 2, (uintptr_t)&item5);
// int item6 = 25;
// dllda_insert(new, 0, (uintptr_t)&item6);
// printItOut(new);
// traverse(new);
// uintptr_t this;
// int code;
// code = dllda_rem(new, 3, &this);
// printf(" %d ", *(int *)this);
// printItOut(new);
// code = dllda_popleft(new, &this);
// printf(" %d ", *(int *)this);
// printItOut(new);
// code = dllda_pop(new, &this);
// printf(" %d ", *(int *)this);
// printItOut(new);
// traverse(new);
int item2 = 4;
dllda_push(new, (uintptr_t)&item2);
// traverse(new);
int item3 = 13;
dllda_push(new, (uintptr_t)&item3);
// traverse(new);
int item6 = 25;
dllda_insert(new, 0, (uintptr_t)&item6);
// printItOut(new);
// traverse(new);
uintptr_t this;
int code;
code = dllda_rem(new, 3, &this);
printf(" %d ", *(int *)this);
// printItOut(new);
code = dllda_popleft(new, &this);
printf(" %d ", *(int *)this);
// printItOut(new);
code = dllda_pop(new, &this);
printf(" %d ", *(int *)this);
// printItOut(new);
// traverse(new);
// return 0;
// }
return 0;
}
+6 -3
View File
@@ -23,20 +23,23 @@ void dllda_pushleft(dllda *c, uintptr_t ptr);
void dllda_push(dllda *c, uintptr_t ptr);
int dllda_insert(dllda *l, int pos, uintptr_t ptr);
// nodeld *adll_find(dllda *l, int i);
// semi hidden node method
nodeld *adll_find(dllda *l, int i);
int dllda_len(dllda *c);
int dllda_query(dllda *l, int i, uintptr_t *copy_here);
int dllda_peekleft(dllda *l, uintptr_t *copy_here);
int dllda_peek(dllda *l, uintptr_t *copy_here);
// int adll_intercept(nodeld *tobeplaced, uintptr_t ptr);
// int adll_insert(nodeld *tobeplaced, uintptr_t ptr);
// int adll_remove(dllda *whatif, nodeld *node);
int dllda_rem(dllda *l, int pos, uintptr_t *puthere);
int dllda_popleft(dllda *l, uintptr_t *puthere);
int dllda_pop(dllda *l, uintptr_t *puthere);
// void traverse(dllda *l);
// void printItOut(dllda *new);
int dllda_to_list(dllda *l, uintptr_t *arr);
#endif