#include<iostream>
using namespace std;

class UP {

public:

ย  ย  bool operator()(int a, int b) {

ย  ย  ย  ย  return (a > b ? true : false);

ย  ย  }

};


class DOWN {

public:

ย  ย  bool operator()(int a, int b) {

ย  ย  ย  ย  return (a < b ? true : false);

ย  ย  }

};


template <class T>

void simple_sort(int* arr, int n, T cmp) {

ย  ย  for (int i = 0; i < n - 1; i++) {

ย  ย  ย  ย  for (int j = i + 1; j < 5; j++) {

ย  ย  ย  ย  ย  ย  if (cmp(arr[i], arr[j]))

ย  ย  ย  ย  ย  ย  ย  ย  arr[i] ^= arr[j] ^= arr[i] ^= arr[j];

ย  ย  ย  ย  }

ย  ย  }

}


void sort_print(int* arr, int n) {

ย  ย  for (int i = 0; i < 5; i++)

ย  ย  ย  ย  cout << arr[i] << " ";

ย  ย  cout << endl;

}


int main(void) {

ย  ย  int arr[5] = { 10, 5, 41, 100, 2 };


ย  ย  DOWN down;

ย  ย  UP up;


ย  ย  simple_sort(arr, 5, down);

ย  ย  sort_print(arr, 5);


ย  ย  simple_sort(arr, 5, up);

ย  ย  sort_print(arr, 5);



ย  ย  return 0;


return 0;

}


์—ฌ๊ธฐ์„œ simple_sortํ•จ์ˆ˜์˜ย arr[i] ^= arr[j] ^= arr[i] ^= arr[j];๋ถ€๋ถ„์ด ์ดํ•ด๊ฐ€ ์•ˆ๋ฉ๋‹ˆ๋‹ค

^= ์—ฐ์‚ฐ์ž๊ฐ€ XOR์ธ ๊ฑด ์•Œ๊ฒ ๋Š”๋ฐ, ์ด๊ฑธ๋กœ ์–ด๋–ป๊ฒŒ ์Šค์™‘์ด ๋˜๋Š”์ง€๋ฅผ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋ฌธํ—Œ์ด๋‚˜ ์กฐ์–ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค