2019-11-09 13:25:30 +00:00
|
|
|
|
#ifndef __CONTEXT_H__
|
|
|
|
|
#define __CONTEXT_H__
|
|
|
|
|
|
|
|
|
|
#include "Strategy.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
class Context
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Context(){
|
2021-10-14 23:49:32 +00:00
|
|
|
|
arr = nullptr;
|
2019-11-09 13:25:30 +00:00
|
|
|
|
N = 0;
|
2021-10-14 23:49:32 +00:00
|
|
|
|
sortStrategy = nullptr;
|
2019-11-09 13:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
Context(int iArr[], int iN){
|
|
|
|
|
this->arr = iArr;
|
|
|
|
|
this->N = iN;
|
2021-10-14 23:49:32 +00:00
|
|
|
|
sortStrategy = nullptr;
|
|
|
|
|
}
|
2021-10-19 16:52:42 +00:00
|
|
|
|
Context(const Context& context) = delete;
|
|
|
|
|
Context& operator=(const Context&) = delete;
|
2021-10-14 23:49:32 +00:00
|
|
|
|
~Context()
|
|
|
|
|
{
|
|
|
|
|
if(sortStrategy)
|
|
|
|
|
{
|
|
|
|
|
delete sortStrategy;
|
|
|
|
|
sortStrategy = nullptr;
|
|
|
|
|
}
|
2019-11-09 13:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
void setSortStrategy(Strategy* iSortStrategy){
|
2021-10-14 23:49:32 +00:00
|
|
|
|
if(sortStrategy)
|
|
|
|
|
{
|
|
|
|
|
delete sortStrategy;
|
|
|
|
|
sortStrategy = nullptr;
|
|
|
|
|
}
|
2019-11-09 13:25:30 +00:00
|
|
|
|
this->sortStrategy = iSortStrategy;
|
|
|
|
|
}
|
|
|
|
|
void sort(){
|
|
|
|
|
this->sortStrategy->sort(arr, N);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
|
|
|
|
|
this->print();
|
|
|
|
|
}
|
|
|
|
|
void setInput(int iArr[], int iN){
|
|
|
|
|
this->arr = iArr;
|
|
|
|
|
this->N = iN;
|
|
|
|
|
}
|
|
|
|
|
void print(){
|
|
|
|
|
for (int i = 0; i < N; i++){
|
|
|
|
|
printf("%3d ", arr[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Strategy* sortStrategy;
|
|
|
|
|
int* arr;
|
|
|
|
|
int N;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // __CONTEXT_H__
|