listCheckList checklist; class Node { //location data } class Edge { public: Node* m_nA; Node* m_nB; Edge* m_eB; bool m_IsTraced; bool m_IsAdded; } void AddEdge(Edge* edge, CheckList& checklist) { for (int i = 0; i < checklist.count(); i++) { if (checklist.getat(i)->m_nB == edge->m_nA) { checklist.getat(i)->m_eB = edge; } } } void Build() { for(int i = 0; i < list.count(); i++) { AddEdge(new Edge(list.getat[i].x1, list.getat[i].y1), CheckList& checklist); } } bool DetectTrace(Edge* edge) { if (edge->m_IsTraced) { edge->m_IsTraced = false; return false; } edge->m_IsTraced = true; bool returnvalue = DetectTrace(edge->m_eB); edge->m_IsTraced = false; return returnvalue; } void Clean() { for (int i = 0; i < checklist.count(); i++) { Edge* test = checklist.getat(i); if (!(test->m_isAdded)) checklist.removeat(i); for (int j = 0; j < checklist.count(); j++) { if (checklist.getat(j)->m_eB == test) checklist.getat(j)->m_eB = null; } } } void Detect() { for(int i = 0; i < checklist.count(); i++) { checklist.getat(i)->m_IsAdded = true; if (!DetectTrace(checklist.getat(i))) checklist.getat(i)->m_IsAdded = false; } } int main() { Build(); Detect(); Clean(); // use checklist as final collection. }