We already know that to swap two integers x and y, we use the following code:
int z = x;
x = y;
y = z;
Replacing int
with t
and using the macro
block structure, we can write swap
as follows.
/* swap: swap two variables x and y of type t */
#define swap(t, x, y) \
t z = x; \
x = y; \
y = z;