public bool RemoveItem(Item item){ if (!items.Contains(item)) return false; items.Remove(item); taken [item.Index] = false; Weight -= item.Weight; Value -= item.Value; return true; }
/// <summary> /// Adds an item to the knapsack. If the knapsack is full, the item will not be added. /// </summary> /// <param name="item">Item.</param> public void AddItem(Item item){ // do not add to the knapsack if it overfills it if (Weight + item.Weight > MaximumCapacity || items.Contains(item)) return; taken [item.Index] = true; Weight += item.Weight; Value += item.Value; items.Add(item); }