Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<malloc.h>
- #include<inttypes.h>
- struct node {
- int *value1, *value2;
- struct node *left_child;
- struct node *right_child;
- struct node *middle_child;
- };
- struct node *new_node(int value1) {
- struct node *tmp = (struct node *)malloc(sizeof(*tmp);
- tmp->value1 = value1;
- tmp->value2 = NULL;
- tmp->left_child = tmp->right_child = tmp->middle_child = NULL;
- return tmp;
- }
- struct node* insert_node(struct node* node, int value) {
- if ((left_child != NULL) & (right_child != NULL)) {
- if (value1 < *node->value1) {
- node->left_child = insert_node(node->left_child, value1);
- node->value1 = malloc(sizeof(*node->value1));
- }
- if (value2 > *node->value2) {
- node->right_child = insert_node(node->right_child, value2);
- node->value2 = malloc(sizeof(*node->value2));
- }
- if ((value1 >= *node->value1) & (value2 <= *node->value2)) {
- if ((value > *node->value1) & (value < *node->value2)) {
- node->middle_child = insert_node(node->middle_child, value);
- node->value = malloc(sizeof(*node->value));
- }
- }
- }
- return node;
- }
- struct node* hmk(struct node* node, int value) { // hmk - how many kids
- uint8_t nbr_ch = !(uintptr_t)node->left_child + !(uintptr_t)node->middle_child + !(uintptr_t)node->right_child)
- if (nbr_ch < 2) {
- if (node->left_child && *node->value1 < value && *node->left_child->value1 > value) {
- int buff = *node->value1;
- *node->value1 = value;
- value = buff;
- }
- new_node(int value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement