AssassinManager(final String[] names) ? This constructor should initialize the A
ID: 3537028 • Letter: A
Question
AssassinManager(final String[] names) ? This constructor should initialize the AssassinManager %u201Ckill ring%u201D with the players in the provided array. The first player (element 0) is targeting the second player (element 1), the second player (element 1) is targeting the third player (element 2), etc., and the last player (element names.length %u2013 1) is targeting the first player (element 0). The %u201Cgraveyard%u201D should begin empty. If the names array is empty, this method should throw an IllegalArgumentException.
This is a constructore and I have an arrayList with names.
Explanation / Answer
class Node{
Node target;
String name;
Node(String n)
{
name=n;
target=null;
}
}
class AssassinManager(final String[] names)
{
Node LinkedList;
//REQUESTED CONSTRUCTOR
AssassinManager(final String[] names)
{
int l=names.length;
LinkedList =new Node(names[0]);
Node prev= LinkedList;
Node current;
for(int i=1;i<l;i++)
{
current = new Node(names[i]);
prev.target = current;
}
current.target = LinkedList;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.