java - Testing my sorting function -


i'm trying sort array of numbers using selectionsort , generics , i'm feeling lost. have interface public t[] sort , public void swap. have fix return sorted array of integers?

my code is:

package sorting;  import java.lang.reflect.array;  public class selectionsort<t extends comparable<t>> implements     iselectionsort<t> {  private t[] array;  @override public t[] sort(t[] array) {     (int = 0; < array.length; i++) {         int k = i;         (int j = 0; j < array.length; j++) {             if ((array[j].compareto(array[k]) == -1))                 k = j;         }         if (k != i)             swap(array, i, k);     }      return null; }  @override public void swap(t[] array, int i, int j) {     t tmp = array[i];     array[i] = array[j];     array[j] = tmp;  }  public static void main(string[] args) {     selectionsort<integer> ss = new selectionsort<integer>();     integer[] array = { 4, 2, 9, 8 };      system.out.println(ss.sort(array)); } } 

start j k:

for (int j = k; j < array.length; j++) { 

return same arary:

return array; 

and print :

    ss.sort(array);     (int = 0; < array.length; i++) {         system.out.println(array[i]);     } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -