bool BTree::open(const char *filename, bool destruct) { if(!db.open(filename, destruct)) return false; if(destruct) { BTreeNode rootnode(numElements, elementSize); BTreeNode leafnode(numElements, elementSize); rootnode.insertElement(MAXKEY, 1); leafnode.insertElement(MAXKEY, 0); rootnode.makeIndex(); leafnode.makeLeaf(0); db.writeRecord(0, rootnode.getbuf()); db.writeRecord(1, leafnode.getbuf()); blockman.setnextblock(2); } else { int j = 2; char *buf = new char[elementSize]; while(db.readRecord(j, buf)) j++; blockman.setnextblock(j); } return true; }
// Driver program to test above functions int main() { struct node* root = NULL; struct Queue* queue = createQueue(SIZE); int i; for(i = 1; i <= 12; ++i) insert(&root,i, queue); printf("The tree elements are: "); levelOrder(root); printf("\nThe number of leaf nodes are %d",leafnode(root)); printf("\nThe number of leaf nodes are %d",fullnode(root)); return 0; }
void print_Huffman_code( minheapNodePTR root , int arr[] , int top ) { if( root -> left ) { arr[top] = 0; print_Huffman_code(root->left,arr,top+1); } if( root -> right ) { arr[top] = 1; print_Huffman_code(root->right,arr,top+1); } if( leafnode(root) ) { int i; for(i = 0; i < top; i++) { if( arr[i] == 0 ) map_char_to_code[root->data - 'A'][i] = '0'; if( arr[i] == 1 ) map_char_to_code[root->data - 'A'][i] = '1'; } } }