0

For my computer science class we need to use the following template code and modify it to do a breadth first search. The code, untouched, already performs a DFS. I know that a breadth first search involves listing all unvisited neighbors of a node before moving on to the next node and repeating. We are supposed to be using a Queue class with peek(), enqueue() and dequeue() methods -- assume these all work correctly.

My code:

/**
 * returns an unvisited neighbor of a node
 * @param n
 * @param v
 * @return
 */
public String getUnvisitedNeighbor (String n, boolean [] v) {
    String neighbor = "";
    int row = contains(n), col = 0;
    while (neighbor == "" && col < nodes.length) {
        if (matrix[row][col] == true) // potentially unvisited neighbor found
            if (v[col] == false) 
                neighbor = nodes[col];
        col++;
    }
    return neighbor;
}

Any ideas as to what I could do about this?

  • 1
    I'm voting to close this question as off-topic because ["Questions asking for homework help must include a **summary of the work you've done so far** to solve the problem, and a **description of the difficulty you are having** solving it."](https://stackoverflow.com/help/on-topic) – azurefrog Apr 06 '20 at 14:13
  • _The code, untouched, already performs a DFS_ please post it. If it performs dfs it must have a `getUnvisitedNeighbors` or similar method – c0der Apr 07 '20 at 05:50

0 Answers0