void CostMap2D::propagateCosts(){ while(!queue_.empty()){ QueueElement* c = queue_.top(); queue_.pop(); unsigned char cost = computeCost(c->distance); updateCellCost(c->ind, cost); // If distance reached the inflation radius then skip further expansion if(c->distance < inflationRadius_) enqueueNeighbors(c->source, c->ind); delete c; } }
int ladderLength(string beginWord, string endWord, unordered_set<string>& wordList) { int steps = 0; unordered_set<string> visited; queue<string> q; q.push(beginWord); visited.insert(beginWord); while (!q.empty()) { steps++; int size = q.size(); for (int i = 0; i < size; i++) { string top = q.front(); q.pop(); if (top == endWord) { return steps; } enqueueNeighbors(top, q, visited, wordList); } } return 0; }