Is this code written in a decent style? Appreciate some feedback : )
private static int Max(int a, int b)
{
return a > b ? a : b;
}
/// <summary>
/// Returns the solution to Knapsack01 problem. Uses bottom up dynamic programming.
/// </summary>
private static int Knapsack01(int capacity, int[] values, int[] weights)
{
int[,] table = new int[values.Length + 1, capacity + 1];
for (int row = 0; row <= values.Length; row++)
{
for (int column = 0; column <= capacity; column++)
{
if (row == 0 || column == 0)
{
// base case
table[row, column] = 0;
}
else if (weights[row -1] <= column)
{
// item fits
int valueAbove = table[row - 1, column];
int spareCapacity = column - weights[row - 1];
int currentValue = values[row - 1] + table[row - 1, spareCapacity];
table[row, column] = Max(valueAbove, currentValue);
}
else
{
// item doesn't fit so copy value from above cell
table[row, column] = table[row - 1, column];
}
}
}
return table[values.Length, capacity];
}