feat(linked list): implemented has value function
This commit is contained in:
parent
0f3334b232
commit
ffa7bd27eb
12 changed files with 23 additions and 1 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -48,6 +48,7 @@ FledastyError fledasty_linked_list_insert_at_index(FledastyLinkedList *current_l
|
|||
FledastyError fledasty_linked_list_insert_before_value(FledastyLinkedList *current_linked_list, void *before_value, void *value);
|
||||
FledastyError fledasty_linked_list_insert_after_value(FledastyLinkedList *current_linked_list, void *after_value, void *value);
|
||||
|
||||
bool fledasty_linked_list_has_value(FledastyLinkedList *current_linked_list, void *value);
|
||||
static inline bool fledasty_linked_list_is_empty(FledastyLinkedList *current_linked_list) { return current_linked_list->size == 0; }
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ FledastyError fledasty_linked_list_insert_after_value(FledastyLinkedList *curren
|
|||
|
||||
if (current_node == current_linked_list->end) {
|
||||
new_node->next = NULL;
|
||||
|
||||
|
||||
current_linked_list->end->next = new_node;
|
||||
current_linked_list->end = new_node;
|
||||
} else {
|
||||
|
|
@ -205,3 +205,20 @@ FledastyError fledasty_linked_list_insert_after_value(FledastyLinkedList *curren
|
|||
current_linked_list->size += 1;
|
||||
return FLEDASTY_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool fledasty_linked_list_has_value(FledastyLinkedList *current_linked_list, void *value) {
|
||||
if (current_linked_list == NULL || value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FledastyLinkedListNode *current_node = current_linked_list->start;
|
||||
while (current_node != NULL) {
|
||||
if (hallocy_compare_memory(current_node->value, value, current_linked_list->element_byte_size)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
current_node = current_node->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,10 @@ int main() {
|
|||
test_linked_list_node = test_linked_list_node->next;
|
||||
}
|
||||
|
||||
if (fledasty_linked_list_has_value(&test_linked_list, &insert_value)) {
|
||||
printf("Linked list contains %d\n", insert_value);
|
||||
}
|
||||
|
||||
if (fledasty_linked_list_is_empty(&test_linked_list)) {
|
||||
printf("Linked list is empty\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue