-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbst.h
57 lines (47 loc) · 1.04 KB
/
bst.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*****************************************************************************
**
** bst.h
**
** Binary search tree definition and interface
**
** Author: Sean Butze
**
****************************************************************************/
#include <stdbool.h>
#ifndef BST_H
#define BST_H
// Binary Tree Node Definition
typedef struct BTNode {
int val;
void *data;
struct BTNode *parent;
struct BTNode *left;
struct BTNode *right;
} BTNode;
/*
* Create and return a new BTNode structure
*/
extern BTNode* BTNode_new(int val, void *data);
// Binary Search Tree Definition
typedef struct BST {
BTNode *head;
} BST;
/*
* Create and return a new empty BST
*/
extern BST* BST_new();
/*
* Search for and return a node with key equal to val
* within the given BST
*
* Returns NULL if no matching node is found
*/
extern BTNode* BST_search(BST *t, int val);
/*
* Insert a new node into a BST
*
* Returns true upon successful insertion,
* false otherwise.
*/
extern bool BST_insert(BST *t, BTNode *node);
#endif