public class main { public static class ee implements comparable<ee> { int x; int[] rac; public ee(int x, int[] rac) { this.x = x; this.rac = rac; } public int compareto(ee that) { if (this.x != that.x) return this.x - that.x; else return this.rac[2] = that.rac[2]; } } public static void main(string[] args) { int [][] ary = { {1,1,3,3}, {1,3,2,4}, {2,3,3,4}}; priorityqueue<ee> pq = new priorityqueue<ee>(); (int[] rec : ary) { ee e1 = new ee(rec[0], rec); ee e2 = new ee(rec[2], rec); pq.add(e1); pq.add(e2); } }
this piece of code i'm running, fine when second loop entered, rec [1, 3, 2, 4] initially, when pq.add(e1) called, value of rec become [1, 3, 3, 4] can explain why happens? thank in advance!
the preoblem in comapreto method:
return this.rac[2] = that.rac[2];
it's returning latter that.rac[2]
. should be:
return this.rac[2] == that.rac[2];
Comments
Post a Comment