feat(doubly linked list): implemented has value function
This commit is contained in:
parent
984f893885
commit
bd6b4b1335
3 changed files with 23 additions and 1 deletions
|
|
@ -48,6 +48,7 @@ FledastyError fledasty_doubly_linked_list_insert_at_index(FledastyDoublyLinkedLi
|
|||
FledastyError fledasty_doubly_linked_list_insert_before_value(FledastyDoublyLinkedList *current_doubly_linked_list, void *before_value, void *value);
|
||||
FledastyError fledasty_doubly_linked_list_insert_after_value(FledastyDoublyLinkedList *current_doubly_linked_list, void *after_value, void *value);
|
||||
|
||||
bool fledasty_doubly_linked_list_has_value(const FledastyDoublyLinkedList *current_doubly_linked_list, void *value);
|
||||
static inline bool fledasty_doubly_linked_list_is_empty(const FledastyDoublyLinkedList *current_doubly_linked_list) { return current_doubly_linked_list->size == 0; }
|
||||
|
||||
#endif
|
||||
|
|
@ -239,3 +239,20 @@ FledastyError fledasty_doubly_linked_list_insert_after_value(FledastyDoublyLinke
|
|||
current_doubly_linked_list->size += 1;
|
||||
return FLEDASTY_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool fledasty_doubly_linked_list_has_value(const FledastyDoublyLinkedList *current_doubly_linked_list, void *value) {
|
||||
if (current_doubly_linked_list == NULL || value == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FledastyDoublyLinkedListNode *current_node = current_doubly_linked_list->start;
|
||||
while (current_node != NULL) {
|
||||
if (hallocy_compare_memory(current_node->value, value, current_doubly_linked_list->element_byte_size)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
current_node = current_node->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,8 +166,12 @@ int main() {
|
|||
test_doubly_linked_list_node = test_doubly_linked_list_node->previous;
|
||||
}
|
||||
|
||||
if (fledasty_linked_list_has_value(&test_linked_list, &insert_value)) {
|
||||
printf("Doubly linked list contains %d\n", insert_value);
|
||||
}
|
||||
|
||||
if (fledasty_doubly_linked_list_is_empty(&test_doubly_linked_list)) {
|
||||
printf("Linked list is empty\n");
|
||||
printf("Doubly linked list is empty\n");
|
||||
}
|
||||
|
||||
fledasty_doubly_list_destroy(&test_doubly_linked_list);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue