I have been trying to figure this for over 3 days now. It is part of my fortnightly assignment for my uni. However, I have hit a road block. Any help will be must appreciated.
Specifics of the assignment, I have figured out so far:
- I must use an Item class that defines (get and set) the weight and value of the stuff
- Table arrayList holds the value and weight of
item array stuffList - Check if the maximum value stuff (Greedy) fits
inside the bag's capacity and add the index of this stuff from the
table arrayList in the bag arrayList - Return bag arrayList.
The method I have written so far (Doesn't seem to be working):
Public static ArrayList <Integer> greedySelection (Item[] stuffList, int Capacity)
{
ArrayList<Integer> bag = new ArrayList<Integer>();
ArrayList<Integer> Table = new ArrayList<Integer>();
for(int i = 0; i < Table.size(); i++){
if(Table.get(i) < Capacity){
bag.add(i);
Table.remove(i);
}
}
return bag;
}