views:

89

answers:

2

Hallo everyone,

i have a list of nodes ListNode and i want to draw a line between two nodes if there is an edge / link between them. My approach so far is:

public void drawGraphInBIM(ref BIM bim)
{
    foreach (Node nodeOuter in ListNode)
    {
     foreach (Node nodeInner in ListNode)
     {
      if (areNodesLinked(nodeOuter, nodeInner))
      {
       bim.drawPolygon(nodeOuter.XYZ, nodeInner.XYZ);
      }
     }
    }
}

I am wandering how the if there is a local copy of ListNode for each loop or is there just a reference and nodeOuter and nodeInner are operating on the same ListNode?

Is there a better approach to this problem?

Cheers,

Dawit

+3  A: 

It's the same ListNode. No local copies are made of reference types.

Justin Grant
+1  A: 

It is the same ListNode collection. You are not copying it.

The reason you're seeing this slow down is because you're current algorithm is O(N^2). It's going to do N^2 iterations for N items, so as your collection grows, the algorithm slows down exponentially.

Reed Copsey