Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/turriform/linked_list_t
https://github.com/turriform/linked_list_t
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/turriform/linked_list_t
- Owner: turriform
- Created: 2024-08-07T01:14:07.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-07T01:35:48.000Z (5 months ago)
- Last Synced: 2024-08-07T03:51:05.954Z (5 months ago)
- Language: C
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
NodeData node_data_t
public:
```
node_data_t *node_data_create(datatype_t datatype, data_t data, size_t data_sz);
```
params usage example:```
int x = 10;
node_data_t *nd = node_data_create(NODE_DATA_PARAMS(x))
```private:
```
nd->free(node_data_t *)
```
frees node_data_t
```
nd->invariant(node_data_t *)
```
sets node_data_t to the default stateNode
Linked List
```
linked_list_t * ll = linked_list_init();
```
Creates empty linked list. Head can be set in 2 ways:
```
ll->set_head(node_t *);
```
by setting head
```
ll->push(node_t *)
```
by pushing nodeSimple usage O(n^2):
```
long int arr[] = {1, 2, 3, 4, 5};
size_t arr_sz = sizeof(arr) / sizeof(*arr);linked_list_t *ll = linked_list_create();
for (size_t i = 0; i != arr_sz; i++)
ll->push(ll, node_create_from_data(NODE_DATA_PARAMS(arr[i])));ll->free(ll);
```
O(n)
```
long int arr[] = {1, 2, 3, 4, 5};
size_t arr_sz = sizeof(arr) / sizeof(*arr);node_t *tail = node_create_from_data(NODE_DATA_PARAMS(arr[0]));
ll->set_head(ll, tail);
for (size_t i = 1; i != arr_sz; i++)
{
tail->add_next(tail, node_create_from_data(NODE_DATA_PARAMS(arr[i])));
tail = tail->next;
}ll->free(ll);
```