-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiway_tree.h
80 lines (68 loc) · 3.04 KB
/
multiway_tree.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
typedef struct entry {
void *data;
struct node *right;
} ENTRY;
typedef struct node {
struct node *first;
int nEntries;
ENTRY *entries;
} NODE;
typedef struct {
int count;
NODE *root;
int (*compare)(void *, void *);
} MULTIWAY_TREE;
/******************************************************************************
* Function: create_multiway_tree
* Description: Creates a new multiway tree
* Parameters: compare - function to compare two entries
* Returns: A pointer to the new tree
/******************************************************************************/
MULTIWAY_TREE *createTree(int (*compare)(void *, void *));
/******************************************************************************
* Function: search_multiway_tree
* Description: Searches for an entry in the tree
* Parameters: tree - the tree to search.
* process to search for the nodes within the tree.
* Returns: A pointer to the entry if found, NULL otherwise
/******************************************************************************/
void *searchTree(MULTIWAY_TREE *tree, void *data);
/******************************************************************************
* Function: recursive_search
* Description: Recursively searches for an entry in the tree
* Parameters: tree - the tree to search.
* node - the node to search
* target - the target to search for
* Returns: A pointer to the entry if found, NULL otherwise
/******************************************************************************/
void *recursiveSearch(MULTIWAY_TREE* tree, NODE *node, void *target);
/******************************************************************************
* Function: insert_multiway_tree
* Description: Inserts an entry into the tree
* Parameters: tree - the tree to insert into.
* data - the data to insert
/******************************************************************************/
void insertTree(MULTIWAY_TREE *tree, void *data);
/******************************************************************************/
/*
* Identifies the leaf to insert the data.
* @param node The root of the tree.
* @param data The data to insert.
* @return The leaf to insert the data.
* @return tree with the data inserted if the data is not in the tree.
*/
/******************************************************************************/
bool insertNode(MULTIWAY_TREE* tree, NODE *node, void *data, ENTRY *upEntry);
/******************************************************************************
* Function: compare
* Description: Compares two entries
* Parameters: data1 - the first entry
* data2 - the second entry
* Returns: 0 if the entries are equal, -1 if data1 < data2, 1 if data1 > data2
/******************************************************************************/
int compare(void *data1, void *data2);
void testCompare();