aisd_lab/lab01/zad3/include/doubly_linked_list.h
2024-03-11 01:16:49 +01:00

35 lines
829 B
C

#ifndef _KIK_ZAD3_DOUBLY_LINKED_LIST_H
#define _KIK_ZAD3_DOUBLY_LINKED_LIST_H
#include <stdbool.h>
#include <stddef.h>
typedef struct Node {
void *value;
struct Node *next;
struct Node *prev;
} Node;
typedef struct {
size_t length;
size_t element_size;
Node *head;
} DoublyLinkedList;
typedef struct {
bool success;
size_t comparisons;
} SearchResult;
DoublyLinkedList doubly_linked_list_new(size_t element_size);
void doubly_linked_list_insert(DoublyLinkedList *l, void *value);
DoublyLinkedList doubly_linked_list_merge(DoublyLinkedList l1, DoublyLinkedList l2);
// direction:
// - true = right
// - false = left
SearchResult doubly_linked_list_search(DoublyLinkedList l, void *value, bool direction, int (*compare_values)(void *v1, void *v2));
#endif // _KIK_ZAD3_DOUBLY_LINKED_LIST_H