Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Wednesday, May 31, 2017

Comparator Example to sort value of class Player



class Checker implements Comparator<Player>
    {
   @Override
   public int compare(Player a,Player b)
       {
       if(a.score==b.score)
           {
           return (a.name.compareTo(b.name));
       }
       else
           {
           if(a.score>b.score)
               return -1;
           else
               return 1;
       }
   }
}

0 Comments:

Post a Comment

Stats