public void sort () {...} - orders the elements of the list in ascending order (according to the order defined by the Comparable interface).

public void sort() { Node<E> small = head; int k = 0; while((small.next)!=null){ if (small.info.compareTo(small.next.info)>0){ small = small.next; k++; Node<E> big = head; int n = 0; while(big.info.compareTo(small.info)<0) { big = big.next; n++; } swap(n,k); } else{ small = small.next; k++; 

I wrote it like this, but he does not want to sort it, why? He even in a normal form does not display a list: (

 public void swap(int i, int j) { if (i < 0 || j < 0 || i >= size || j >= size) { throw new IndexOutOfBoundsException(); } if (i > j) { int t = i; i = j; j = t; } Node<E> prevI = find(new Node(head), i); Node<E> nodeI = prevI.next; Node<E> nextI = nodeI.next; Node<E> prevJ = find(prevI, j - i); Node<E> nodeJ = prevJ.next; Node<E> nextJ = nodeJ.next; System.out.println(nodeI.info + " " + nodeJ.info); if (i + 1 == j) { prevI.next = nodeJ; nodeJ.next = nodeI; nodeI.next = nextJ; } else { prevI.next = nodeJ; nodeJ.next = nextI; prevJ.next = nodeI; nodeI.next = nextJ; } if (i == 0) { head = nodeJ; } } 
  • Show the implementation of the swap method (please add it to your question) - Vadik
  • @Vadik, I added - Maxim Gorky

0