DesignPattern/22.StrategyPattern/2.Code/main.cpp

31 lines
524 B
C++
Raw Normal View History

2019-11-09 13:25:30 +00:00
#include "Context.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
Context* ctx = new Context();
int arr[] = { 10, 23, -1, 0, 300, 87, 28, 77, -32, 2 };
ctx->setInput(arr, sizeof(arr)/sizeof(int));
2020-11-29 02:02:40 +00:00
printf("input:");
2019-11-09 13:25:30 +00:00
ctx->print();
2020-11-29 02:02:40 +00:00
// BubbleSort
2019-11-09 13:25:30 +00:00
ctx->setSortStrategy(new BubbleSort());
ctx->sort();
2020-11-29 02:02:40 +00:00
// SelectionSort
2019-11-09 13:25:30 +00:00
ctx->setSortStrategy(new SelectionSort());
ctx->sort();
2020-11-29 02:02:40 +00:00
// InsertSort
2019-11-09 13:25:30 +00:00
ctx->setSortStrategy(new InsertSort());
ctx->sort();
printf("\n\n");
system("pause");
2020-11-29 02:02:40 +00:00
delete ctx;
2019-11-09 13:25:30 +00:00
return 0;
}