#include <stdio.h>
void swap(int *x, int *y)
{
*y = *x ^ *y;
*x = *x ^ *y;
*y = *x ^ *y;
}
void revert(int *a, int len)
{
int first = 0, last = len - 1;
for (;first < last; first++, last--)
swap(&a[first], &a[last]);
}
int main()
{
int i, a[] = {1 ,2, 3, 4, 5};
revert(a, 5);
for (i = 0; i < 5; i++)
printf("%2d", a[i]);
getch();
}
两数交换不借助第三变量
最新推荐文章于 2023-02-02 16:35:42 发布