Demo entry 6771739

fds

   

Submitted by anonymous on Nov 20, 2018 at 08:50
Language: C++. Code size: 867 Bytes.

#pragma once

#include <stdint.h>
#include <math.h>

template<typename T>
struct _BiTree
{
    T d;
    struct _BiTree* l;
    struct _BiTree* r;
};

typedef struct _BiTree<int> BiNode;
typedef struct _BiTree<int> *BiTree;

BiTree MakeEmpty(BiTree t)
{
    if (t != NULL)
    {
        MakeEmpty(t->l);
        MakeEmpty(t->r);
        free(T);
    }
    return NULL;
}

BiNode* Find(int x, BiTree t)
{
    BiNode *tmp = NULL;

    if (t == NULL)
        return NULL;

    if (t->d == x)
    {
        tmp = t;
    }
    if (tmp == NULL)
    {
        tmp = Find(x, t->l);
    }
    if (tmp == NULL)
    {
        tmp = Find(x, t->r);
    }
    return tmp;
}
BiNode* FindMin(int x, BiTree t);
BiNode* FindMax(int x, BiTree t);
BiTree Insert(int x, BiTree t);
BiTree Delete(int x, BiTree t);
int Retrieve(BiNode* n);

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).