NODE * MYNULL1;
NODE * MYNULL2;
MYNULL1 = &MYNULL1;
MYNULL2 =&MYNULL2 ;
//BECAUSE MYNULL2 AND MYNULL1 IS IN THE STACK, THOSE ADDESS WILL NOT BE ALLOCATED AGAIN. IT IS SAFE TO USE IT AS NULL.
1. go to the end of link1. change the next field of every node to MYNULL when going. remember the address of last node in Var A. NEXT FIELD OF Last node is NULL OR MYNULL for sure.
O(n)
2. from the start of link2 go, change the next field of every node to MYNULL2 when going. if you can find MYNULL . return true.
O(n)
3. return false WHEN SEE NEXT FIELD NULL OR MYNULL2
TOTAL O(2N)
change the next field of every node to MYNULL when going is the key to prevent close loop.
NODE * MYNULL2;
MYNULL1 = &MYNULL1;
MYNULL2 =&MYNULL2 ;
//BECAUSE MYNULL2 AND MYNULL1 IS IN THE STACK, THOSE ADDESS WILL NOT BE ALLOCATED AGAIN. IT IS SAFE TO USE IT AS NULL.
1. go to the end of link1. change the next field of every node to MYNULL when going. remember the address of last node in Var A. NEXT FIELD OF Last node is NULL OR MYNULL for sure.
O(n)
2. from the start of link2 go, change the next field of every node to MYNULL2 when going. if you can find MYNULL . return true.
O(n)
3. return false WHEN SEE NEXT FIELD NULL OR MYNULL2
TOTAL O(2N)
change the next field of every node to MYNULL when going is the key to prevent close loop.