#define MYNULL 0X00000001
#define MYNULL2 0X00000002
//SUPPOSE THIS IS 32BIT INTEL COMPUTER. FOR OTHER PROCESSOR, THERE ARE ALWAYS OTHER WAY SIMILARE WAY.
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.
#define MYNULL2 0X00000002
//SUPPOSE THIS IS 32BIT INTEL COMPUTER. FOR OTHER PROCESSOR, THERE ARE ALWAYS OTHER WAY SIMILARE WAY.
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.