1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct node_t node_t;
struct node_t {
void * data;
struct node_t * lc, * rc ;
};
node_t ** bintree;
void bt_add_value(node_t ** bt, int v){
while(*bt != NULL){
printf("a");
if( *(int*)((*bt)->data) < v)
bt= &((*bt)->rc);
else
bt= &((*bt)->lc);
}
printf("b");
*bt = malloc (1 * sizeof **bt);
assert(*bt);
*(int*)((*bt)->data) = v;
(*bt)->lc = (*bt)->rc = NULL;
}
int main (void){
*(int*)((*bintree)->data) = 5;
(*bintree)->lc = NULL;
(*bintree)->rc = NULL;
bt_add_value(bintree,10);
return 0;
} |
Partager