From 6a55384ce9f247182159ce92b88a203ecca16dcb Mon Sep 17 00:00:00 2001 From: realstealthninja <68815218+realstealthninja@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:52:59 +0530 Subject: [PATCH] fix: use dynamic array instead of vla in knapsack --- greedy_algorithms/knapsack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/greedy_algorithms/knapsack.cpp b/greedy_algorithms/knapsack.cpp index 74be4fee0..b5e9f6374 100644 --- a/greedy_algorithms/knapsack.cpp +++ b/greedy_algorithms/knapsack.cpp @@ -44,7 +44,7 @@ int main() { cout << "\n Enter the number of Items : "; int n; cin >> n; - Item itemArray[n]; + Item *itemArray = new Item[n]; for (int i = 0; i < n; i++) { cout << "\nEnter the weight and profit of item " << i + 1 << " : "; cin >> itemArray[i].weight; @@ -73,6 +73,6 @@ int main() { } cout << "\nMax Profit : " << maxProfit; - + delete[] itemArray; return 0; }