本文整理汇总了C++中PQueue::top方法的典型用法代码示例。如果您正苦于以下问题:C++ PQueue::top方法的具体用法?C++ PQueue::top怎么用?C++ PQueue::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PQueue
的用法示例。
在下文中一共展示了PQueue::top方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
PQueue<int> q;
int* a = new int[SIZE];
unsigned int i;
// fill array with random integers
for(i = 0; i < SIZE; i++) {
a[i] = rand()%(SIZE*4);
}
int* p = a;
// insert all items
for( i = 0; i < SIZE; i++) {
//cout << "Inserting: " << *(p+i) << "\n";
q.push(*(p+i));
}
// add all elements to result array
vector<int> result;
while(!q.empty()) {
int * temp = q.top();
q.pop();
result.push_back(*temp);
delete temp;
}
// unsigned int k;
// for (k = 0; k < result.size(); k++) {
// cout << " " << result[k];
// }
// cout << endl;
// If result is not sorted, something went wrong
// uncomment above code to view all elements inline
unsigned int l;
bool fail = false;
for (l = 1; l < result.size() ; l++) {
if (result[l-1] > result[l]) {
cout << "LIST NOT SORTED, FAILURE" << endl;
fail = true;
}
}
if (!fail) {
cout << "Test was successful, integers were sorted" << endl;
}
delete[] a;
return 0;
}