Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1-2
- 1-4
- 2-3
- 3-6
- 4-5
- 5-6
- private static void bfs() {
- boolean[] visited = new boolean[virsotnes.length];
- Queue<Integer> queue = new LinkedList<>();
- String[] pathTo = new String[virsotnes.length];
- for (int v=1; v < visited.length; v++) {
- if (!visited[v]) {
- pathTo[v] = v+"";
- System.out.println("nSTARTING AT " + virsotnes[v].virs);
- queue.clear();
- bfs(v, visited, queue,pathTo);
- }
- }
- }
- private static void bfs(int start, boolean[] visited,Queue<Integer>queue,String []pathTo) {
- visited[start] = true;
- System.out.println("visiting " + virsotnes[start].virs);
- queue.add(start);
- while (!queue.isEmpty()) {
- int v = queue.remove();
- //System.out.print(v+"this is v");
- for (Neighbor nbr=virsotnes[v].virsotne; nbr != null; nbr=nbr.next) {
- int vnum = nbr.vertexNum;
- if (!visited[vnum]) {
- System.out.println("n" + virsotnes[v].virs + "--" + virsotnes[vnum].virs);
- visited[vnum] = true;
- queue.add(vnum);
- pathTo[vnum] = pathTo[v] + vnum;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement