本文整理汇总了C++中BinaryTree::getFirst方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::getFirst方法的具体用法?C++ BinaryTree::getFirst怎么用?C++ BinaryTree::getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::getFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decompress
std::string* Huffman::decompress(const std::vector<bool>* input) {
encode = false;
if(encoding == NULL || encoding->data == NULL || encoding->freqs == NULL)
throw "no encoding set";
encoded = (void*)(new std::string());
LL* linkedlist = new LL();
unsigned int ll_size = 0;
for(unsigned int i = 0; i < encoding->data->size(); i++) {
linkedlist->insert(new Node(new char(encoding->data->at(i)), encoding->freqs->at(i)));
ll_size++;
}
BinaryTree* bst = new BinaryTree(linkedlist, ll_size);
Node* curr_node = bst->getFirst();
for(unsigned int i = 0; i < input->size() - overflow; i++) {
if(!input->at(i)) {
if(curr_node->left != NULL)
curr_node = curr_node->left;
}else if(input->at(i)) {
if(curr_node->right != NULL)
curr_node = curr_node->right;
}
if(curr_node->left == NULL && curr_node->right == NULL) {
if(curr_node->character != NULL) {
const char tmp[] = {*(curr_node->character), '\0'};
*((std::string*)encoded) += std::string(tmp);
}
curr_node = bst->getFirst();
}
}
delete linkedlist;
delete bst;
return (std::string*)encoded;
}