From e6ea047a59053ed908ed44b1a099801a88b36d59 Mon Sep 17 00:00:00 2001 From: Florian Burgener <florian.burgener@etu.hesge.ch> Date: Tue, 11 Jan 2022 13:43:10 +0100 Subject: [PATCH] Remove compare --- circ_list.c | 8 ++++---- circ_list.h | 4 ++-- circ_list_tests.c | 10 +++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/circ_list.c b/circ_list.c index f090080..93c2c34 100644 --- a/circ_list.c +++ b/circ_list.c @@ -62,7 +62,7 @@ element *list_insert_before(element *head, int data) { return list_insert_after(iterator, data); } -element *list_search(element *head, int data, int (*compare)(int, int)) { +element *list_search(element *head, int data) { if (list_empty(head)) { return NULL; } @@ -70,7 +70,7 @@ element *list_search(element *head, int data, int (*compare)(int, int)) { element *iterator = head; do { - if (compare(iterator->data, data)) { + if (iterator->data == data) { return iterator; } @@ -81,8 +81,8 @@ element *list_search(element *head, int data, int (*compare)(int, int)) { } // This function cannot work when the element to be removed is the head. -element *list_remove(element *head, int data, int (*compare)(int, int)) { - element *el = list_search(head, data, compare); +element *list_remove(element *head, int data) { + element *el = list_search(head, data); if (el == NULL) { return NULL; diff --git a/circ_list.h b/circ_list.h index fc413ce..278e7eb 100644 --- a/circ_list.h +++ b/circ_list.h @@ -14,8 +14,8 @@ unsigned int list_count(element *head); element *list_move(element *head); element *list_insert_after(element *head, int data); element *list_insert_before(element *head, int data); -element *list_search(element *head, int data, int (*compare)(int, int)); -element *list_remove(element *head, int data, int (*compare)(int, int)); +element *list_search(element *head, int data); +element *list_remove(element *head, int data); void list_free(element *head); void list_process(element *head, int (*action)(int)); diff --git a/circ_list_tests.c b/circ_list_tests.c index ffc4198..3cdc78b 100644 --- a/circ_list_tests.c +++ b/circ_list_tests.c @@ -5,10 +5,6 @@ #include "circ_list.h" -int compare_equality(int element, int data) { - return element == data; -} - int action_add_10(int element) { return element + 10; } @@ -61,10 +57,10 @@ int main() { assert(list_count(list) == 3); // list_search - element *search_result_1 = list_search(list, 1, compare_equality); + element *search_result_1 = list_search(list, 1); assert(search_result_1->data == 1); - element *search_result_2 = list_search(list, 4, compare_equality); + element *search_result_2 = list_search(list, 4); assert(search_result_2 == NULL); // list_process @@ -78,7 +74,7 @@ int main() { // list_remove printf("list_remove\n"); - element *removed_element_1 = list_remove(list, 13, compare_equality); + element *removed_element_1 = list_remove(list, 13); assert(removed_element_1->data == 13); assert(list->data == 12); assert(list->next->data == 11); -- GitLab