DFS
This commit is contained in:
		
							parent
							
								
									03599e5d6f
								
							
						
					
					
						commit
						f00d27589b
					
				@ -478,8 +478,30 @@ class Graphs {
 | 
			
		||||
    path = path.reversed.toList();
 | 
			
		||||
 | 
			
		||||
    //print("Shortest path between vertices ${startDot+1} and ${goalDot+1} is: $path");
 | 
			
		||||
    if (path[0]==startDot && path[1]==goalDot && !_dots[startDot].hasConnection(goalDot+1)) return null;
 | 
			
		||||
    if (path[0] == (startDot+1) &&
 | 
			
		||||
        path[1] == (goalDot+1) &&
 | 
			
		||||
        !_dots[startDot].hasConnection(goalDot + 1)) return null;
 | 
			
		||||
    return path;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  List<bool>? dfsIterative(int v) {
 | 
			
		||||
    v--;
 | 
			
		||||
    List<bool> label = <bool>[];
 | 
			
		||||
    for (int i = 0; i < _amount; i++) {
 | 
			
		||||
      label.add(false);
 | 
			
		||||
    }
 | 
			
		||||
    List<int> stack = <int>[];
 | 
			
		||||
    stack.add(v);
 | 
			
		||||
    while (stack.isNotEmpty) {
 | 
			
		||||
      v = stack.removeLast();
 | 
			
		||||
      if (!label[v]) {
 | 
			
		||||
        label[v] = true;
 | 
			
		||||
        for (int i in _dots[v].getL().keys) {
 | 
			
		||||
          stack.add(i-1);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return label;
 | 
			
		||||
  }
 | 
			
		||||
  //************Алгоритмы************
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user