I trying to rewrite a particular method (see below). This method is a constructor that takes in an ArrayList as a parameter. The ArrayList should add names into the object in the exact order as they appear. Each new node should be added to the end of the linked list.
First version:
public AssassinManager(ArrayList<String> players) {
if (players == null || players.isEmpty()) { throw new IllegalArgumentException(); }
killring = new AssassinNode(players.get(0)); // create first node - for the killring
AssassinNode node = killring;
for (int i = 1; i < players.size(); i++) { // Add a new node at the end of each killing
node.next = new AssassinNode(players.get(i));
node = node.next;
}
}
The new version:
private KillList killring;
private AssassinNodeData graveyard;
public AssassinManager(ArrayList<String> players) {
if (players == null || players.isEmpty()) { throw new IllegalArgumentException(); }
killring = new KillList(players.get(0));
KillList node = killring;
// some code
}
KillList extends LinkedList<AssassinNodeData> Now I'm trying to achieve the same thing without using next.
Any suggestions or solutions is greatly appreciated!
