We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a16a4bc commit 6a55384Copy full SHA for 6a55384
greedy_algorithms/knapsack.cpp
@@ -44,7 +44,7 @@ int main() {
44
cout << "\n Enter the number of Items : ";
45
int n;
46
cin >> n;
47
- Item itemArray[n];
+ Item *itemArray = new Item[n];
48
for (int i = 0; i < n; i++) {
49
cout << "\nEnter the weight and profit of item " << i + 1 << " : ";
50
cin >> itemArray[i].weight;
@@ -73,6 +73,6 @@ int main() {
73
}
74
75
cout << "\nMax Profit : " << maxProfit;
76
-
+ delete[] itemArray;
77
return 0;
78
0 commit comments