02-11-2022
08:04 PM
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
02-11-2022
08:04 PM
From what I understand from the translation and reading the code is that you are trying to find a path between 2 nodes in a network by defining the number of elements in-between? (int y=21;) this is not efficient and could easily give you the wrong path if there are multiple paths in the network with the same number of elements. The code has no way to decide which end (shower in this case) it should find, you should think of providing a selection of 2 ends and try to find the path between them.
The code has a bunch of problems, it would be a lot of work to correct it, but I've made some comments that might help:
public List<ElementId> RunStepThroughElements(List<ElementId> eIds)
{
eIds = m_lVistited; //Overwriting the functions parameter eIds means that you don't need the parameter in the first place
if (pPrev != null)
{
ConnectorSet pConnset = GetConnectors(pPrev);
foreach (Connector pConn in pConnset)
{
if (pConn.IsConnected)
{
// Get the connector connected to current connector
c = GetConnectedConnector(pConn);
if (c != null)
{
Element prNext = c.Owner;
m_lVistited.Add(prNext.Id);
pPrev = prNext;
}
}
}
m_iLoops++; //using a class member as a counter does not seem like a good practice
}
int y = 21; //hard coded value? what if you have more that 21 elements?
if ((m_lVistited.Count <= m_lSelectedElts.Count)
&& (m_iLoops <= MAX_LOOPS))
{
RunStepThroughElements(eIds); //Running the function again on the same group of elements? This will provide no progress
if (eIds.Count != y)
{
RunStepThroughElements(eIds);
}
}
return m_lVistited;
}
Also it might be worth a while to read up on Inorder Traversal Of an N-ary Tree
Hope this helps!