# Implement a function int count keys(tree node t *tree, key t a, ke...

## Question

Implement a function
int count keys(tree node t *tree, key t a, key t b);
that counts the keys x with a ≤ x ≤ b in the leaf nodes of the given search tree. The function should work with the given code for a height-balanced tree. Do not include the code of the height-balanced tree in your submission; submit only the code you wrote yourself.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>

#define BLOCKSIZE 256

typedef int object_t;
typedef int key_t;
typedef struct tr_n_t { key_t key;
struct tr_n_t *left;
struct tr_n_t *right;
int          height;
} tree_node_t;

tree_node_t *currentblock = NULL;
int    size_left;
tree_node_t *free_list = NULL;

tree_node_t *get_node()
{ tree_node_t *tmp;
if( free_list != NULL )
{ tmp = free_list;
free_list = free_list -> left;
}
else
{ if( currentblock == NULL || size_left == 0)
{ currentblock =
(tree_node_t *) malloc( BLOCKSIZE * sizeof(tree_node_t) );
size_left = BLOCKSIZE;
}
tmp = currentblock++;
size_left -= 1;
}
return( tmp );
}

void return_node(tree_node_t *node)
{ node->left = free_list;
free_list = node;
}

tree_node_t *create_tree(void)
{ tree_node_t *tmp_node;
tmp_node = get_node();
tmp_node->left = NULL;
return( tmp_node );
}

void left_rotation(tree_node_t *n)
{ tree_node_t *tmp_node;
key_t       tmp_key;
tmp_node = n->left;
tmp_key = n->key;
n->left = n->right;
n->key   = n->right->key;
n->right = n->left->right;
n->left->right = n->left->left;
n->left->left = tmp_node;
n->left->key   = tmp_key;
}...

By purchasing this solution you'll be able to access the following files:
SolutionTree.c and SolutionCountKeys.c.

\$43.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.