Skip to content

Commit 2df9ee3

Browse files
author
=
committed
Fractional knapsack code updated
1 parent c0c5ed0 commit 2df9ee3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

greedy/fractionalknapsack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ while(bag>0)
5252
{
5353
for(i=0;i<n;i++)
5454
{
55-
if(bag>weight[i])
55+
///////
56+
if (bag==0)
57+
break;
58+
//////
59+
else if(bag>weight[i])
5660
{
5761
bag=bag-weight[i];
5862
p=p+profit[i];

0 commit comments

Comments
 (0)