aisd_lab/lab1/zad3/include/doubly_linked_list.h

39 lines
940 B
C
Raw Normal View History

2024-03-11 01:16:49 +01:00
#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;
Node *tail;
2024-03-11 01:16:49 +01:00
} DoublyLinkedList;
typedef struct {
bool success;
size_t comparisons;
} SearchResult;
DoublyLinkedList doubly_linked_list_new(size_t element_size);
// value is copied into a local queue-owned variable
// in rust terms - value is only borrowed
2024-03-11 01:16:49 +01:00
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