i made the linked list its not from java collections and i put in it many methods .. my linked list worked like the original one but theres a small differences my class have a print and sort methods my input is : [5,18,3,10,2] ... or it can be a string inputs .. i want the sort method to sort the linked list , so the output should be like this : [2,3,5,10,18] or a sorted string here is the sort method code :
public void sort(){
Node<E> current = head ;
Node<E> current2 = current.next;
E min = head.element;
E temp;
int pos = 0;
for (int i = 0; i < size-1; i++) {
for (int j = 0; j < size; j++) {
if(current2 != null){
if(min.compareTo(current2.element) > 0){
pos = j ;
min = current2.element;
}
current2= current2.next;
}
}
temp = current.element;
current.element = min;
current = current.next;
min = current.element;
current2 = head;
for (int j = 0; j <= pos; j++) {
if(current2 !=null){
if(j==pos){current2.element = temp;}
current2= current2.next;
}
}
current2 = current.next;
}
}
i tried so hard but it didnt workWhat doesn't work? Is there any error? If yes, please post the full stacktrace here. Also, it would be useful to have a minimal complete example which demonstrates the issue.print()on anLinkedList, but aLinkedListhas no methodprint().