Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void swapSigned(int *a, int *b)
- {
- /** 1st method: sum and subtraction swap
- * Beware of overflow if using high values.
- */
- *a=*a+*b;
- *b=*a-*b;
- *a=*a-*b;
- }
- void swap(int *a, int *b)
- {
- /** 2nd method: boolean swap
- * It completely avoids overflow.
- */
- *a=(*a)&(*b);
- *b=(*a)&(*b);
- *a=(*a)&(*b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement