void MinHblt<T>::LevelOrder(HbltNode<T>* t) {
    Queue<HbltNode<T> *> q;
    while (t != NULL) {
        Visit_(t);
        if (t->left_ != NULL)
            q.push(t->left_);
        if (t->right_ != NULL)
            q.push(t->right_);
        if (q.Empty()) {
            return;
        }
        else {
            t = q.Remove();
        }
    }
}
Beispiel #2
0
void Router::propagate(Coordinate *source, Coordinate *target){
  int stepId = 0;
  queue->Add(source);
  visit(source, stepId);
  Coordinate *current;
  GridPoint currentGridPoint;
  bool targetFound = false;

  do{
    //get the next node from queue
    current = queue->Remove();
    currentGridPoint = getGridPointAt(current);
    stepId = currentGridPoint.StepId + 1;
    //get neighbors of source
    Coordinate *neighbors = current->GetNeighbors();

    int i;
    //if any of them is the target, stop,
    for (i = 0; i < 4; i++) {
      if(neighbors[i].Equals(target)){
        visit(&neighbors[i], stepId);
        targetFound = true;
        break;
      }

      //add it to the queue if 
      //it is not out of bounds
      //it is not visited
      if(neighbors[i].InBound(rows, cols) && !isVisited(&neighbors[i])){
        queue->Add(&neighbors[i]);
        visit(&neighbors[i], stepId);
      }

    }
  }while(!queue->IsEmpty() && !targetFound);

  //else add them to the queue
  //do the same with the rest of the elements in the queue until the target is
  //reached

}