public bool findPath(int n1, int depth) { if (n1 == dest) { return(true); //找到目的元器件端口 } if (depth-- == 0) { return(false); //超过搜索深度 } if (used[n1]) { return(false); //已经遍历过此结点 } used[n1] = true; //标志位置true for (int i = 0; i < elmList.Count; i++) { CircuitElm ce = getElm(i); //获取元器件 if (ce.Equals(firstElm)) { continue; //若是第一个元器件 pass } if (type == VOLTAGE) //若既不是导线也不是电源则继续 { if (!(ce.isWire() || ce.type == TYPES.VoltageElm)) { continue; } } //若当前元器件没有与此结点相连 int j; for (j = 0; j < ce.getPostCount(); j++) { if (ce.getNode(j) == n1) { break; } } if (j == ce.getPostCount()) { continue; } for (int k = 0; k < ce.getPostCount(); k++) { if (j == k) { continue; } if (ce.getConnection(j, k) && findPath(ce.getNode(k), depth)) { used[n1] = false; return(true); } } } used[n1] = false; return(false); }