feat(ll)!: add new ll function and rename insert
ds_*ll_insert -> ds_*ll_append to better reflect what it does and there is now ds_*ll_add to add data anywhere in the ll.
This commit is contained in:
parent
46b0219ab4
commit
69dc1dcb45
4 changed files with 104 additions and 16 deletions
18
test.c
18
test.c
|
|
@ -30,29 +30,35 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
test("sll",
|
||||
char *a = "one";
|
||||
char *a = "a";
|
||||
char *b = "b";
|
||||
|
||||
ds_sll_t *tmp;
|
||||
it("creates a new linked list", tmp = ds_sll_init());
|
||||
free(tmp);
|
||||
|
||||
ds_sll_t *ll = ds_sll_new_node(a);
|
||||
it("inserts an invalid item", ds_sll_insert(ll, NULL) == -1);
|
||||
it("appends an invalid item", ds_sll_append(ll, NULL) == -1);
|
||||
it("removes an invalid index", ds_sll_remove(&ll, 1234) == NULL);
|
||||
it("removes an item", a == ds_sll_remove(&ll, 0));
|
||||
it("adds an item to the beginning", ds_sll_add(&ll, b, 0) == 0);
|
||||
it("removes an item", b == ds_sll_remove(&ll, 0));
|
||||
ds_sll_remove(&ll, 0);
|
||||
);
|
||||
|
||||
test("dll",
|
||||
char *a = "one";
|
||||
char *a = "a";
|
||||
char *b = "b";
|
||||
|
||||
ds_dll_t *tmp;
|
||||
it("creates a new linked list", tmp = ds_dll_init());
|
||||
free(tmp);
|
||||
|
||||
ds_dll_t *ll = ds_dll_new_node(a);
|
||||
it("inserts an invalid item", ds_dll_insert(ll, NULL) == -1);
|
||||
it("appends an invalid item", ds_dll_append(ll, NULL) == -1);
|
||||
it("removes an invalid index", ds_dll_remove(&ll, 1234) == NULL);
|
||||
it("removes an item", a == ds_dll_remove(&ll, 0));
|
||||
it("adds an item to the beginning", ds_dll_add(&ll, b, 0) == 0);
|
||||
it("removes an item", b == ds_dll_remove(&ll, 0));
|
||||
ds_dll_remove(&ll, 0);
|
||||
);
|
||||
|
||||
test("hmp",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue