2015-04-05 22:32:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "intavltree.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int cmp(const void *v1,const void*v2)
|
|
|
|
{
|
2015-05-01 00:16:54 +02:00
|
|
|
return *((int*)v1) - *((int*)v2);
|
2015-04-05 22:32:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void del(void* d)
|
|
|
|
{
|
|
|
|
free (d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
struct mavl * intavltree_create()
|
2015-04-05 22:32:12 +02:00
|
|
|
{
|
2018-03-11 00:56:41 +01:00
|
|
|
return mavl_create(cmp,del,100);
|
2015-04-05 22:32:12 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
int * intavltree_add(struct mavl * t, int val)
|
2015-04-05 22:32:12 +02:00
|
|
|
{
|
2015-05-01 00:16:54 +02:00
|
|
|
int *v = mavl_get(t,&val);
|
2015-04-05 22:32:12 +02:00
|
|
|
if (v)
|
|
|
|
return v;
|
|
|
|
|
|
|
|
v = malloc(sizeof(int));
|
|
|
|
if (!v)
|
|
|
|
return NULL;
|
|
|
|
*v=val;
|
2022-07-18 01:15:17 +02:00
|
|
|
return mavl_insert(t,v,NULL);
|
2015-04-05 22:32:12 +02:00
|
|
|
}
|