java - Sorting an array of objects by two doubles -
so had delimited file read array.
array[0] boxid (double)
and
array[1] movieid (double)
i have no clue how i'd able sort array these 2 doubles. comments? i've tried looking @ other questions on website got confused them. i'm in first programming class.
movies[] newmastermovies = new movies[200]; int newmastercount = 0; int mastercount = 0; int updatecount = 0; while (updatecount < updatetotalcounter || mastercount < mastertotalcounter) { string updatecompare = updatemovies[updatecount].getboxid() + updatemovies[updatecount].getmovieid(); string mastercompare = mastermovies[mastercount].getboxid() + mastermovies[mastercount].getmovieid(); int compare = updatecompare.compareto(mastercompare); if (compare > 0) { newmastermovies[newmastercount] = mastermovies[mastercount]; mastercount++; newmastercount++; } if (updatemovies[updatecount].getactioncode() == "a") { newmastermovies[newmastercount] = updatemovies[updatecount]; updatecount++; newmastercount++; } if (updatemovies[updatecount].getactioncode() == "d") { updatecount++; mastercount++; } if (updatemovies[updatecount].getactioncode() == "c") { newmastermovies[newmastercount] = updatemovies[updatecount]; updatecount++; newmastercount++; mastercount++; } }
that array looks trying sort. tried selection sort got confused since want sort 2 properties, not one.
this guy here wonders
arrays.sort(iarr);
here can do: here example code
public class arraydemo { public static void main(string[] args) { // initializing unsorted int array int iarr[] = {2, 1, 9, 6, 4}; // let print elements available in list (int number : iarr) { system.out.println("number = " + number); } // sorting array arrays.sort(iarr); // let print elements available in list system.out.println("the sorted int array is:"); (int number : iarr) { system.out.println("number = " + number); } } }
and results should this
number = 2
number = 1
number = 9
number = 6
number = 4
the sorted int array is:
number = 1
number = 2
number = 4
number = 6
number = 9
hopes helps some
Comments
Post a Comment