this is a big fix, not a small fix

This commit is contained in:
ldlda authored and lda committed 2024-12-05 17:40:47 +07:00
1 parent ad3ce0bd48
commit efe7783b78
2 files changed
+95 -16

No files matched your search

+70 -16
View File
@@ -52,9 +52,13 @@ int adll_remove(dllda *whatif, nodeld *node)
{
// start = right
whatif->start = node->next;
if (whatif->start == whatif->end)
whatif->end = NULL; // ass font
// left of right now is null
whatif->start->prev = NULL;
// eq to line below
if (whatif->start != NULL)
whatif->start->prev = NULL;
}
// no right!
else if (node->next == NULL || node == whatif->end) // b
@@ -62,8 +66,8 @@ int adll_remove(dllda *whatif, nodeld *node)
// end is now left
whatif->end = node->prev;
// right of left now is null
whatif->end->next = NULL;
// eq to line below too like
if (whatif->end != NULL)
whatif->end->next = NULL;
}
whatif->size--;
@@ -231,6 +235,11 @@ int dllda_popleft(dllda *l, uintptr_t *puthere)
};
*puthere = startMayBeNull->ptr;
adll_remove(l, startMayBeNull);
if (dllda_len(l) == 1)
{
if (l->start == NULL)
;
};
return 0;
}
@@ -304,10 +313,10 @@ void printItOut(dllda *new)
printf("size: %d [", sz);
uintptr_t *c = (uintptr_t *)calloc(sz, sizeof(uintptr_t));
for (int i = sz - dllda_to_list(new, c);
printf("(%d: %d)", i, *(int *)c[i]) &&
(++i < sz); // how to get value
printf(", "))
;
(i < sz); // how to get value
i++,
(i < sz) && printf(", "))
printf("(%d: %d)", i, *(int *)c[i]);
printf("]\n");
}
void traverse(dllda *l)
@@ -348,7 +357,30 @@ int dllda_to_list(dllda *l, uintptr_t *arr)
return len;
}
int _main(int argc, char const *argv[])
int dllda_into_list(dllda *l, uintptr_t *arr)
{
int len = dllda_len(l);
for (int i = 0; i < len; i++)
{
uintptr_t *t = &(arr[i]);
dllda_popleft(l, t);
// printf("%d ", *(int*) *t);
}
return len;
}
int dllda_from_list(dllda *l, uintptr_t *arr, int size)
{
for (int i = 0; i < size; i++)
// printf("%p %d ", arr[i], *(int *)arr[i]);
dllda_push(l, arr[i]);
// printf("%d ", *(int*) *t);
return 0;
}
int main(int argc, char const *argv[])
{
dllda *new = initlda();
int dsa = 17;
@@ -378,18 +410,40 @@ int _main(int argc, char const *argv[])
dllda_insert(new, 0, (uintptr_t)&item6);
// printItOut(new);
// traverse(new);
uintptr_t this;
uintptr_t this1, this2, this3;
int code;
code = dllda_rem(new, 3, &this);
printf(" %d ", *(int *)this);
code = dllda_rem(new, 3, &this1);
printf(" %d ", *(int *)this1);
// printItOut(new);
code = dllda_popleft(new, &this);
printf(" %d ", *(int *)this);
code = dllda_popleft(new, &this2);
printf(" %d ", *(int *)this2);
// printItOut(new);
code = dllda_pop(new, &this);
printf(" %d ", *(int *)this);
code = dllda_pop(new, &this3);
printf(" %d ", *(int *)this3);
// printItOut(new);
// traverse(new);
printf("\n");
int item7 = 11;
dllda_insert(new, 2, (uintptr_t)&item7);
int item8 = 42;
dllda_insert(new, 1, (uintptr_t)&item8);
int item9 = 16;
dllda_insert(new, 3, (uintptr_t)&item9);
dllda_push(new, this1);
dllda_push(new, this2);
dllda_pushleft(new, this3);
printItOut(new);
printf("\n");
int len = dllda_len(new);
uintptr_t *list = calloc(len, sizeof(uintptr_t));
dllda_into_list(new, list);
for (int i = 0; i < len; i++)
printf("%d ", *(int *)list[i]);
printf("\n");
printItOut(new);
printf("a\n");
dllda_from_list(new, list, len);
printItOut(new);
return 0;
}