java - Created the same program where one uses generics and the other ints but the generics one does not work -


i creating program class sorts 2d array faster teacher's implementation.

i decided put data bst , remove each minimum element , put new sorted array. however, i've been having trouble wrote using int instead of t, when did program worked!

however, converted use generic type t, no longer sorting correctly. class below i've written , inherits method sort(t[][] input) teacher's class hybridsort.

i believe problem lies somewhere in way i've been dealing generic type t , treating int (i use x.compareto(y) don't believe problem). can post code wrote using int if necessary. thanks!

public class ***<t extends comparable<t>> implements hybridsort<t> {  public class bst {     public t value;     public bst left;     public bst right;     public bst root;      public bst() {         this.value = null;         this.left = null;         this.right = null;     }      public bst(t value, bst left, bst right) {         this.value = value;         this.left = left;         this.right = right;     }      public void insert(t value) {         root = insert(root, new bst(value, null, null));         this.value = root.value;         this.left = root.left;         this.right = root.right;     }      public bst insert(bst parent, bst newindex) {         if (parent == null) return newindex;         else if (newindex.value.compareto(parent.value) != 1) parent.left = insert(parent.left, newindex);         else if (newindex.value.compareto(parent.value) > 0) parent.right = insert(parent.right, newindex);         return parent;     }      public t removemin() {         bst current = root;         bst parent = root;          while (current.left != null) {             parent = current;             current = current.left;         }         parent.left = current.left;          return current.value;     } }  @suppresswarnings("unchecked") public t[] sort(t[][] input) {     bst bst = new bst();     int size = arrays.stream(input).maptoint(t -> t.length).sum();     t[] output = (t[])array.newinstance(input[0][0].getclass(), size);      (int = 0; < input.length; i++) {         (int j = 0; j < input[0].length; j++) {             bst.insert(input[i][j]);         }     }     (int = 0; < output.length; i++) {         output[i] = (t)(integer)bst.removemin();     }      return output; } 

}


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -