5.16 iterSearch
element* iterSearch(treePointer tree, int k) {
while(tree) {
if(k == tree->data.key) return &(tree->data);
if(k < tree->data.key)
tree = tree->leftChild;
else
tree = tree->rightChild;
}
return NULL;
}
5.17 insert
void insert(treePointer *node, int k, iType theItem) {
treePointer ptr, temp = modifiedSearch(*node, k);
if(temp || !(*node)) {
ptr = (treePointer)malloc(sizeof(treePointer));
ptr->data.key = k;
ptr->data.item = theItem;
ptr->leftChild = ptr->rightChild = NULL;
if(*node) {
if(k < temp->data.key) temp->leftChild = ptr;
else temp->rightChild = ptr;
}
else *node = ptr;
}
}
5.1 inorder
void inorder(treePointer ptr) {
if(ptr) {
inorder(ptr->leftChild);
printf("%d", ptr->data);
inorder(ptr->rightChild);
}
}
linked binary tree’s declaration
typedef enum {not, and, or, true, false} logical;
typedef struct node *treePointer;
typedef struct {
treePointer leftChild;
logical data;
short int value;
treePointer rightChild;
} node;
element’s declaration
#define MAX_ELEMENTS 200
#define HEAP_FULL(n) (n == MAX_ELEMENTS-1)
#define HEAP_EMPTY(n) (!n)
typedef struct {
int key;
//other feild
} element;
element heap[MAX_ELEMENTS];
int n = 0;