a = a+b-(b=a) OR a = a^b^(b=a) And both of them will work also for chars and stuff ….
Category: Algorithms
Detect cycle in a linked list
ptr1 = ptr2 = head; do{ ptr1 = ptr1 -> next; ptr2 = ptr2 -> next -> next; }while(ptr1 != ptr2); ptr2 is iterating along the list with double the speed of ptr1. If there is any cycle, then ptr1Continue reading… Detect cycle in a linked list