リストをランダムにシャッフルしようとしています。コードをテストしようとするたびに、本質的に何もせず、終了しません。私は正確に何が欠けているのか、間違っているのか疑問に思っていました。
public static ListElement shuffle(ListElement head){
int n= ListUtils.getLength(head);
ListElement head2= null;
while( head != null) {
int random = (int) Math.random() * n;
for(int i=0;i<random;i++){
ListElement list= new ListElement();
list=getItem(head2,n);
list.getNext();
head2=list;
}
}
return head2;
}
GetItem
public static ListElement getItem(ListElement head, int n){
if(n == 0){
return head;
}else if(head == null){
return null;
}else{
return getItem(head.getNext(),n-1);
}
}