#include <iostream>
using namespace std;
class SortRule
{
public:
bool operator()(int num1, int num2) const
{
if (num1 > num2) return true;
else return false;
}
};
class AscendingSort : public SortRule
{
public:
bool operator()(int num1, int num2) const
{
if (num1 > num2) return true;
else return false;
}
};
class DescendingSort : public SortRule
{
public:
bool operator()(int num1, int num2) const
{
if (num1 < num2) return true;
else return false;
}
};
class DataStorage // for int data
{
private:
int* arr;
int idx;
const int MAX_LEN;
public:
DataStorage(int arrlen) :idx(0), MAX_LEN(arrlen)
{
arr = new int[MAX_LEN];
}
void AddData(int num)
{
if (MAX_LEN <= idx) {
cout << "더 이상 저장이 불가능합니다." << endl;
return;
}
arr[idx++] = num;
}
void Show()
{
for (int i = 0; i < idx; i++) cout << arr[i] << ' ';
cout << endl;
}
void SortData(const SortRule& functor)
{
for (int i = 0; i < (idx - 1); i++)
{
for (int j = 0; j < (idx - 1) - i; j++)
{
if (functor(arr[j], arr[j + 1]))
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
};
int main()
{
DataStorage arr(5);
arr.AddData(10);
arr.AddData(50);
arr.AddData(20);
arr.AddData(30);
arr.AddData(40);
arr.SortData(AscendingSort());
arr.Show();
}