Skip to content
Snippets Groups Projects
Commit e6ea047a authored by florian.burgener's avatar florian.burgener
Browse files

Remove compare

parent f8693ea6
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,7 @@ element *list_insert_before(element *head, int data) { ...@@ -62,7 +62,7 @@ element *list_insert_before(element *head, int data) {
return list_insert_after(iterator, 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)) { if (list_empty(head)) {
return NULL; return NULL;
} }
...@@ -70,7 +70,7 @@ element *list_search(element *head, int data, int (*compare)(int, int)) { ...@@ -70,7 +70,7 @@ element *list_search(element *head, int data, int (*compare)(int, int)) {
element *iterator = head; element *iterator = head;
do { do {
if (compare(iterator->data, data)) { if (iterator->data == data) {
return iterator; return iterator;
} }
...@@ -81,8 +81,8 @@ element *list_search(element *head, int data, int (*compare)(int, int)) { ...@@ -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. // 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 *list_remove(element *head, int data) {
element *el = list_search(head, data, compare); element *el = list_search(head, data);
if (el == NULL) { if (el == NULL) {
return NULL; return NULL;
......
...@@ -14,8 +14,8 @@ unsigned int list_count(element *head); ...@@ -14,8 +14,8 @@ unsigned int list_count(element *head);
element *list_move(element *head); element *list_move(element *head);
element *list_insert_after(element *head, int data); element *list_insert_after(element *head, int data);
element *list_insert_before(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_search(element *head, int data);
element *list_remove(element *head, int data, int (*compare)(int, int)); element *list_remove(element *head, int data);
void list_free(element *head); void list_free(element *head);
void list_process(element *head, int (*action)(int)); void list_process(element *head, int (*action)(int));
......
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
#include "circ_list.h" #include "circ_list.h"
int compare_equality(int element, int data) {
return element == data;
}
int action_add_10(int element) { int action_add_10(int element) {
return element + 10; return element + 10;
} }
...@@ -61,10 +57,10 @@ int main() { ...@@ -61,10 +57,10 @@ int main() {
assert(list_count(list) == 3); assert(list_count(list) == 3);
// list_search // 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); 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); assert(search_result_2 == NULL);
// list_process // list_process
...@@ -78,7 +74,7 @@ int main() { ...@@ -78,7 +74,7 @@ int main() {
// list_remove // list_remove
printf("list_remove\n"); 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(removed_element_1->data == 13);
assert(list->data == 12); assert(list->data == 12);
assert(list->next->data == 11); assert(list->next->data == 11);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment