本文整理汇总了C++中DataType::getPriority方法的典型用法代码示例。如果您正苦于以下问题:C++ DataType::getPriority方法的具体用法?C++ DataType::getPriority怎么用?C++ DataType::getPriority使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataType
的用法示例。
在下文中一共展示了DataType::getPriority方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: logic_error
void Heap<DataType,KeyType,Comparator>:: insert ( const DataType &newDataItem ) throw ( logic_error )
// Inserts newDataItem into a heap. This data item is initially
// inserted as the bottom rightmost data item in the heap. It is then
// moved upward until a valid heap is produced.
{
int parentj, // Array indices that move together up the heap
j;
// Requires that heap is not full
if ( size >= maxSize )
throw logic_error ("heap is full");
// YOUR CODE GOES HERE
// Hint: you may want to use the 2 variables declared above (but you don't have to)
// Hint: call getPriority() to get the priority of a data item (e.g. newDataItem.getPriority())
else if (size==0){
dataItems[size]=newDataItem;
size++;
}
else if (size<maxSize && size>0){
DataType parent;
DataType temp;
int x = size;
dataItems[x]=newDataItem;
DataType data=dataItems[x];
parent = dataItems[(x-1)/2];
while(data.getPriority() > parent.getPriority()){
temp=dataItems[x];
dataItems[x]=parent;
parent = temp;
dataItems[(x-1)/2]=parent;
x=(x-1)/2;
if(x<0){
break; }
else{
parent = dataItems[(x-1)/2];
}
}
size++;
}
}