void main() { node_t* pnode1 = create_node(1); node_t* pnode2 = create_node(2); node_t* pnode3 = create_node(3); node_t* pnode4 = create_node(4); node_t* pnode5 = create_node(5); node_t* pnode6 = create_node(6); node_t* pnode7 = create_node(7); /*List1*/ connect(pnode1, pnode2); connect(pnode2, pnode3); connect(pnode3, pnode6); connect(pnode6, pnode7); /*List2*/ connect(pnode4, pnode5); connect(pnode5, pnode6); node_t* pHead1 = pnode1; node_t* pHead2 = pnode4; node_t* common_node = FindFirstCommonNode(pHead1, pHead2); printf("The first common node is %d\n", common_node->m_nKey); }
void Test(char* testName, ListNode* pHead1, ListNode* pHead2, ListNode* pExpected) { if(testName != NULL) printf("%s begins: ", testName); ListNode* pResult = FindFirstCommonNode(pHead1, pHead2); if(pResult == pExpected) printf("Passed.\n"); else printf("Failed.\n"); }