本文整理汇总了C++中BinaryHeap::size方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryHeap::size方法的具体用法?C++ BinaryHeap::size怎么用?C++ BinaryHeap::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryHeap
的用法示例。
在下文中一共展示了BinaryHeap::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeElement
void removeElement(BinaryHeap<int> & h, int index){
cout<< "Removing the number a position " << index << " from the heap." <<endl;
int x = h.remove(index);
cout<< x << " was successfully removed."<<endl;
int size = h.size();
cout<<"The size of the heap is now: "<<size<<endl;
}
示例2: execute_new_sell_order
void execute_new_sell_order(MarketInstruction * mi) {
MarketInstruction * mostImportantBuyOrder = NULL;
while(buyOrders->size() > 0) {
if(mi->quantity == 0) break;
mostImportantBuyOrder = buyOrders->rootElem();
if(mi->price <= mostImportantBuyOrder->price) {
unsigned int quantity = min(mi->quantity, mostImportantBuyOrder->quantity);
mi->quantity -= quantity;
mostImportantBuyOrder->quantity -= quantity;
double price = mostImportantBuyOrder->price;
fill(quantity, price, mostImportantBuyOrder->id, mi->id, mi->targetAssetName);
if(mostImportantBuyOrder->quantity == 0) {
buyOrders->deleteRootElem();
free(mostImportantBuyOrder);
}
}
else
break;
}
if(mi->quantity > 0) {
rest_order(mi);
}
}
示例3: search
void Pathfinder::search()
{
init();
BinaryHeap openHeap;
mStart->g = 0;
mStart->h = manhattan(mStart, mGoal);
mStart->opened = true;
openHeap.push(mStart);
while (openHeap.size() > 0)
{
// Pop the node with the smallest f value
Node* currentNode = openHeap.pop();
// Check if we hit the target
if (currentNode == mGoal)
{
// Compute the path and exit
generatePath(currentNode);
return;
}
currentNode->closed = true;
std::vector<Node*> neighbors = getNeighborsAdjacentTo(currentNode);
for (int i = 0; i < neighbors.size(); i++)
{
Node* neighbor = neighbors[i];
if (neighbor->closed || neighbor->worldRef->getMaterial()->isCollidable())
continue;
int gScore = currentNode->g + 1;
if(!neighbor->opened || gScore < neighbor->g)
{
neighbor->g = currentNode->g + 1;
neighbor->h = manhattan(currentNode, neighbor);
neighbor->parent = currentNode;
neighbor->opened = true;
openHeap.push(neighbor);
}
}
}
}
示例4: repeatedBackwardAStar
void repeatedBackwardAStar(bool** maze, int size, State* start, State* goal){
int counter = 0;
State** S = new State*[size];
for (int i = 0; i < size; i++){
S[i] = new State[size];
}
for (int r = 0; r < size; r++){
for (int c = 0; c < size; c++){
S[r][c].row = r;
S[r][c].col = c;
S[r][c].search = 0;
}
}
while (!compareStatePos(start, goal)){
counter = counter + 1;
S[start->row][start->col].g = INF;
S[start->row][start->col].search = counter;
S[goal->row][goal->col].g = 0;
S[goal->row][goal->col].h = manhattanDistance(start, goal);
S[goal->row][goal->col].f = goal->g + goal->h;
S[goal->row][goal->col].search = counter;
BinaryHeap OPEN;
list<State> CLOSED;
// watch 4 states around the start state to update cost, if any
if (start->row > 0 && !maze[start->row - 1][start->col]){
updateCostToInf(S, size, start->row - 1, start->col);
}
if (start->row< size - 1 && !maze[start->row + 1][start->col]){
updateCostToInf(S, size, start->row + 1, start->col);
}
if (start->col > 0 && !maze[start->row][start->col - 1]){
updateCostToInf(S, size, start->row, start->col - 1);
}
if (start->col < size - 1 && !maze[start->row][start->col + 1]){
updateCostToInf(S, size, start->row, start->col + 1);
}
OPEN.insert(S[goal->row][goal->col]);
computePath(S, maze, start, &OPEN, &CLOSED, counter, size, false);
if (OPEN.size() == 0){
cout << "I cannot reach the target\n";
// clean up
for (int i = 0; i < size; i++){
delete[] S[i];
}
delete[] S;
return;
}
// follow the tree-pointers from sstart to sgoal
//stack<coord> path;
coord current;
current.row = start->row;
current.col = start->col;
//path.push(curCoord);
while (current.row != goal->row || current.col != goal->col){
int curRow = current.row;
int curCol = current.col;
// watch 4 states around this current state to update cost, if any
if (current.row > 0 && !maze[current.row - 1][current.col]){
updateCostToInf(S, size, current.row - 1, current.col);
}
if (current.row < size - 1 && !maze[current.row + 1][current.col]){
updateCostToInf(S, size, current.row + 1, current.col);
}
if (current.col > 0 && !maze[current.row][current.col - 1]){
updateCostToInf(S, size, current.row, current.col - 1);
}
if (current.col < size - 1 && !maze[current.row][current.col + 1]){
updateCostToInf(S, size, current.row, current.col + 1);
}
coord next;
next.row = S[curRow][curCol].treeRow;
next.col = S[curRow][curCol].treeCol;
int dir = direction(¤t, &next);
cout << "\tTried to move to: (" << next.row << ", " << next.col << ")... ";
if (S[current.row][current.col].cost[dir] > 1){
cout << "BLOCKED" << endl;
start = &S[current.row][current.col];
break;
}
cout << "OK! Moved start to: (" << next.row << ", " << next.col << ")" << endl;
current = next;
}
start = &S[current.row][current.col];
}
//.........这里部分代码省略.........
示例5: getSize
void getSize(BinaryHeap<int> &h){
int size = h.size();
cout<<"The size of the heap is: " << size<< endl;
}