本文整理汇总了C++中BinaryHeap::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryHeap::isEmpty方法的具体用法?C++ BinaryHeap::isEmpty怎么用?C++ BinaryHeap::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryHeap
的用法示例。
在下文中一共展示了BinaryHeap::isEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//need this to compare two BinaryTreePtr Objects
//bool BinaryTreePtr::operator<(const BinaryTreePtr& b) const
//{
// return frequency < b.frequency;
//}
int main(int argc, char** argv)
{
ifstream inf(argv[1]);
char character;
//BinaryTreePtr p;
int ascii[256] = {};
int temp[256];
int counter = 0;
BinaryHeap <BinaryTreePtr> heap; //not sure what size
while (inf.get(character)) //reads each character as char
{
int num_char = (int)character; //casts char into int
ascii[num_char]++; //increments array based on asci
}
for (int j = 0; j < 256; j++)
{
if (ascii[j] != 0)
{
int freq = ascii[j];
heap.insert(BinaryTreePtr((char)j,ascii[j]));
}
}
while(!heap.isEmpty())
{
BinaryTreePtr min_1;
heap.deleteMin(min_1);
//cout << (char)min_1.asci_value << min_1.frequency << endl;
if (heap.isEmpty())
{
heap.insert(min_1);
break;
}
else
{
BinaryTreePtr min_2;
heap.deleteMin(min_2);
// cout << (char)min_2.asci_value << min_2.frequency << endl;
BinaryTreePtr parent;
int temp_freq = min_1.Node->getInfo() + min_2.Node->getInfo();
char temp_char = 'Y';
BinaryTreePtr Parent(temp_char, temp_freq, min_1.Node, min_2.Node);
heap.insert(Parent);
}
}
char* random = new char[500]();
int i = 0;
BinaryTreePtr last;
heap.deleteMin(last);
last.Node->print(random, i);
}
示例2: main
int main(int argc, char **argv) {
BinaryHeap<int> testHeap;
std::string input;
std::string numbers = "0123456789";
std::cout << "Input vals to add to BinaryHeap (val1 val2 val3 val4 ... end)\n";
while (std::cin >> input)
{
// if 'std::String::find_first_not_of' doesnt find anything, then it outputs max_int (long int)
// since any num higher than 1 will be set to true, add 1 to max int to start at 0(false)
if (input.find_first_not_of(numbers)+1 ) {
if (input == "end")
{
break;
}
else
{
std::cerr << input << " not recognized\n";
continue;
}
} // end if
int num = std::atoi(input.c_str()); // transform string into number, would have normally use boost::lexical_cast though
testHeap.insert(num);
}
std::cout << "Input vals to remove from BinaryHeap (val1 val2 val3 val4 ... end)\n";
while (std::cin >> input)
{
// if 'std::String::find_first_not_of' doesnt find anything, then it outputs max_int (long int)
// since any num higher than 1 will be set to true, add 1 to max int to start at 0(false)
if (input.find_first_not_of(numbers)+1 ) {
if (input == "end")
break;
else
{
std::cerr << input << " not recognized\n";
continue;
}
} // end if
int num = std::atoi(input.c_str());
testHeap.removeKey(num);
}
std::cerr << "\n";
while (!testHeap.isEmpty())
{
std::cerr << testHeap.findMin() << " ";
testHeap.deleteMin();
}
std::cerr << "\n";
return 0;
}
示例3: find_min_dist_id
int find_min_dist_id(BinaryHeap<HeapVt> & heap_vt, const vector<Vertex> & vt_path) {
HeapVt tmp_vt(-1, -1);
do{
if(heap_vt.isEmpty()) {
return -1;
}
heap_vt.deleteMin(tmp_vt);
}while(true == vt_path[tmp_vt.id].known);
return tmp_vt.id;
}
示例4: writeHeap
void Encoder::writeHeap(stringstream &out, BinaryHeap<HuffmanNode *> heap, int elements) const
{
out << elements; // store how many heap elements at beginning
HuffmanNode *node; // to store temporary node
while(!heap.isEmpty())
{
heap.deleteMin(node);
out << node->data;
out << node->frequency;
} // traverse the entire heap
return;
} // writeHeap()