int _tmain(int argc, _TCHAR* argv[]) { //Swap two integers, passing by reference int i = 1; int j = 2; swap(i, j); std::cout << "i = " << i << std::endl; std::cout << "j = " << j << std::endl; //Swap two "Data" structs, passing by reference Data a = { 10, 20 }; Data b = { 30, 40 }; swap(a, b); std::cout << "a.x = " << a.x << std::endl; std::cout << "a.y = " << a.y << std::endl; std::cout << "b.x = " << b.x << std::endl; std::cout << "b.y = " << b.y << std::endl; Data *c = &a; Data *d = &b; pswap(c, d); std::cout << "c->x = " << c->x << std::endl; std::cout << "c->y = " << c->y << std::endl; std::cout << "d->x = " << d->x << std::endl; std::cout << "d->y = " << d->y << std::endl; return 0; }
void insertionSort(real *arr, int *perm, int startndx, int endndx, int direction) { int i, j; if (direction >= 0) { for (i = startndx; i <= endndx; i++) { j = i; while (j > startndx && arr[j - 1] > arr[j]) { Swap(&arr[j], &arr[j-1]); pswap(&perm[j], &perm[j-1]); j--; } } } if (direction < 0) { for (i = startndx; i <= endndx; i++) { j = i; while (j > startndx && arr[j - 1] < arr[j]) { Swap(&arr[j], &arr[j-1]); pswap(&perm[j], &perm[j-1]); j--; } } } }
int main() { int A = 10, B = 20; int *pA, *pB; pA = &A, pB = &B; printf("pA가 가리키는 변수 : %d\n", *pA); printf("pB가 가리키는 변수 : %d\n\n", *pB); pswap(&pA, &pB); printf("pA가 가리키는 변수 : %d\n", *pA); printf("pB가 가리키는 변수 : %d\n", *pB); return 0; }