diff --git a/21.StatePattern/2.Code/main.cpp b/21.StatePattern/2.Code/main.cpp index 99b8e48..cfbcfc4 100644 --- a/21.StatePattern/2.Code/main.cpp +++ b/21.StatePattern/2.Code/main.cpp @@ -6,11 +6,14 @@ int main() GameAccount *jungle = new GameAccount("Jungle"); for (int i = 0; i < 5; i++){ - printf("第%d局:\n", i + 1); + printf("%d \n", i + 1); jungle->playCard(); } printf("\n\n"); system("pause"); + + delete jungle; + return 0; } \ No newline at end of file diff --git a/22.StrategyPattern/2.Code/main.cpp b/22.StrategyPattern/2.Code/main.cpp index 01f3bfd..e41924a 100644 --- a/22.StrategyPattern/2.Code/main.cpp +++ b/22.StrategyPattern/2.Code/main.cpp @@ -7,22 +7,25 @@ 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)); - printf("输入:"); + printf("input:"); ctx->print(); - // 冒泡排序 + // BubbleSort ctx->setSortStrategy(new BubbleSort()); ctx->sort(); - // 选择排序 + // SelectionSort ctx->setSortStrategy(new SelectionSort()); ctx->sort(); - // 插入排序 + // InsertSort ctx->setSortStrategy(new InsertSort()); ctx->sort(); printf("\n\n"); system("pause"); + + delete ctx; + return 0; } \ No newline at end of file diff --git a/23.TemplateMethodPattern/2.Code/main.cpp b/23.TemplateMethodPattern/2.Code/main.cpp index ffca5f3..9900170 100644 --- a/23.TemplateMethodPattern/2.Code/main.cpp +++ b/23.TemplateMethodPattern/2.Code/main.cpp @@ -5,15 +5,18 @@ int main() { FingerprintModule *fp = new FingerprintModuleA(); fp->algorithm(); + delete fp; fp = new FingerprintModuleB(); fp->algorithm(); + delete fp; fp = new FingerprintModuleC(); fp->algorithm(); - + delete fp; printf("\n\n"); system("pause"); + return 0; } \ No newline at end of file diff --git a/24.VisitorPattern/2.Code/main.cpp b/24.VisitorPattern/2.Code/main.cpp index c0abea7..605c221 100644 --- a/24.VisitorPattern/2.Code/main.cpp +++ b/24.VisitorPattern/2.Code/main.cpp @@ -29,8 +29,16 @@ int main() printf("\n\n"); shoppingCart->accept(cashier); - printf("\n\n"); system("pause"); + + delete apple1; + delete apple2; + delete book1; + delete book2; + delete cashier; + delete jungle; + delete shoppingCart; + return 0; } \ No newline at end of file