本文整理汇总了C++中Heap::PrintHeap方法的典型用法代码示例。如果您正苦于以下问题:C++ Heap::PrintHeap方法的具体用法?C++ Heap::PrintHeap怎么用?C++ Heap::PrintHeap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap::PrintHeap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: heapsort
/* the char* filename is just for printing the name, the file is opened and dealt with in the main() */
void heapsort(vector<int> &sortingvector, int number_of_elements, char* filename){
/* Heap myHeap; .//declare a Heap instance here */
Heap myHeap;
/* Using the sortingvector, INSERT elements into the Heap */
for(unsigned int i = 0; i < sortingvector.size(); ++i)
myHeap.InsertHeap(sortingvector[i]);
/* After building the heap from the file, PRINT the current state of the heap before sorting */
cout << "Heap before sorting: " << filename << endl;
myHeap.PrintHeap();
/* STORE how many comparisons were made until this point */
int insertComparisons = myHeap.GetComparisons();
myHeap.ResetComparisons();
/* DELETE elements from the Heap, copying it back to the vector in a way that it is sorted */
for(unsigned int i = 0; i < sortingvector.size(); ++i) {
int temp = myHeap.Delete();
if(temp > 0) sortingvector[i] = temp;
}
/* STORE how many comparisons were made for the deletion process */
int deleteComparisons = myHeap.GetComparisons();
/* PRINT the number of comparisons for the Insert and Deletion tasks */
cout << "InsertHeap: " << insertComparisons << " comparisons" << endl;
cout << "DeleteRoot: " << deleteComparisons << " comparisons" << endl;
/* Print the state of the vector after sorting */
cout << "Vector after sorting:" << endl;
for(unsigned int i = sortingvector.size() - 1; i > 0; --i)
cout << sortingvector[i] << ' ';
cout << sortingvector[0] << ' ';
cout << endl;
}