bool checkNeighbors(point currentPoint, grid * theGrid) { int row = currentPoint.getRow(); int column = currentPoint.getColumn(); int currentValue = theGrid->getValue(row,column); int status; if (row != 0) { // Neighbor to the north (Canada) status = checkPosition(row-1, column, currentValue, theGrid); if (status == 99) return true; else if (status == 1) pointQueue.enqueue(point(row-1,column)); } if (row < theGrid->getSize() -1) { // Neighbor to the south (Mexico) status = checkPosition(row+1, column, currentValue, theGrid); if (status == 99) return true; else if (status == 1) pointQueue.enqueue(point(row+1,column)); } if (column != 0) { // Neighbor to the west (Pacific) status = checkPosition(row, column-1, currentValue, theGrid); if (status == 99) return true; else if (status == 1) pointQueue.enqueue(point(row,column-1)); } if (column < theGrid->getSize() -1) { // Neighbor to the east (Atlantic) status = checkPosition(row, column+1, currentValue, theGrid); if (status == 99) return true; else if (status == 1) pointQueue.enqueue(point(row,column+1)); } return false; }
point checkNeighborsBackward(point currentPoint, grid * theGrid) { int row = currentPoint.getRow(); int column = currentPoint.getColumn(); int currentValue = theGrid->getValue(row,column); point nextPoint(row,column); if (row != 0) { // Neighbor to the north (Canada) if (theGrid->getValue(row-1,column) == currentValue-1) { nextPoint = point(row-1,column); pointStack.push(&nextPoint); return nextPoint; } } if (row < theGrid->getSize() -1) { // Neighbor to the south (Mexico) if (theGrid->getValue(row+1,column) == currentValue-1) { nextPoint = point(row+1,column); pointStack.push(&nextPoint); return nextPoint; } } if (column != 0) { // Neighbor to the west (Pacific) if (theGrid->getValue(row,column-1) == currentValue-1) { nextPoint = point(row,column-1); pointStack.push(&nextPoint); return nextPoint; } } if (column < theGrid->getSize() -1) { // Neighbor to the east (Atlantic) if (theGrid->getValue(row,column+1) == currentValue-1) { nextPoint = point(row,column+1); pointStack.push(&nextPoint); return nextPoint; } } return NULL; }
bool point::operator !=(point & other) { if ((other.getRow() == row) && (other.getColumn() == column)) return false; else return true; }