https://github.com/amiralles/avl_tree
AVL Tree implementation written in C
https://github.com/amiralles/avl_tree
Last synced: 3 months ago
JSON representation
AVL Tree implementation written in C
- Host: GitHub
- URL: https://github.com/amiralles/avl_tree
- Owner: amiralles
- License: mit
- Created: 2018-07-11T13:51:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T14:32:11.000Z (almost 7 years ago)
- Last Synced: 2025-01-09T14:44:49.779Z (4 months ago)
- Language: C
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## AVL Tree
Minimalist implementation of [AVL Tree](https://en.wikipedia.org/wiki/AVL_tree) written in C.## How to use it
Here is an example on how to use this library.
For convenience is just a header file. Include it in your project and you'd
be ready to roll.``` C
#include
#include
#include "./avltree.h"int main(void) {
struct avl_node* root = NULL;// Insert a million items.
printf("Adding items...\n");
for (int i = 0; i < 1000 * 1000; ++i) {
void *data = malloc(sizeof(int));
*((int*)data) = i;
root = avl_insert(root, i, data);
}
printf("Done!\n\n");// Search for a particular key.
int key = 789321;
printf("Searching %i...\n", key);
struct avl_node* n = avl_search(root, key);// Print value.
printf("Key: %i\n", key);
printf("Value: %i\n", *(int *)n->data);
printf("Tree height: %i\n", n->height);
printf("Done!\n\n");
return 0;
}
```