Advertisement
cflare

detectedgecycles

May 31st, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1.     list<Edge*>CheckList checklist;
  2.  
  3.     class Node
  4.     {
  5.         //location data
  6.     }
  7.  
  8.     class Edge
  9.     {
  10.     public:
  11.         Node* m_nA;
  12.         Node* m_nB;
  13.         Edge* m_eB;
  14.         bool m_IsTraced;
  15.     bool m_IsAdded;
  16.     }
  17.  
  18.     void AddEdge(Edge* edge, CheckList& checklist)
  19.     {
  20.         for (int i = 0; i < checklist.count(); i++)
  21.         {
  22.             if (checklist.getat(i)->m_nB == edge->m_nA)
  23.             {
  24.                 checklist.getat(i)->m_eB = edge;
  25.             }
  26.         }
  27.     }
  28.  
  29.     void Build()
  30.     {
  31.         for(int i = 0; i < list.count(); i++)
  32.         {
  33.             AddEdge(new Edge(list.getat[i].x1, list.getat[i].y1), CheckList& checklist);
  34.         }
  35.     }
  36.  
  37.     bool DetectTrace(Edge* edge)
  38.     {
  39.         if (edge->m_IsTraced)
  40.         {
  41.             edge->m_IsTraced = false;
  42.             return false;
  43.         }
  44.         edge->m_IsTraced = true;
  45.         bool returnvalue = DetectTrace(edge->m_eB);
  46.         edge->m_IsTraced = false;
  47.         return returnvalue;
  48.     }
  49.  
  50.     void Clean()
  51.     {
  52.         for (int i = 0; i < checklist.count(); i++)
  53.         {
  54.             Edge* test = checklist.getat(i);
  55.             if (!(test->m_isAdded)) checklist.removeat(i);
  56.             for (int j = 0; j < checklist.count(); j++)
  57.             {
  58.                 if (checklist.getat(j)->m_eB == test) checklist.getat(j)->m_eB = null;
  59.             }
  60.         }
  61.     }
  62.  
  63.     void Detect()
  64.     {
  65.         for(int i = 0; i < checklist.count(); i++)
  66.         {
  67.         checklist.getat(i)->m_IsAdded = true;
  68.             if (!DetectTrace(checklist.getat(i))) checklist.getat(i)->m_IsAdded = false;
  69.         }
  70.     }
  71.  
  72.     int main()
  73.     {
  74.         Build();
  75.         Detect();
  76.         Clean();
  77.         // use checklist as final collection.
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement