Advertisement
mouhsineelachbi

sortRT_Collision WimaxProject

Apr 20th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.*;
  2. class Main {
  3.   public static ArrayList<Utilisateur> sortRT_Collision(ArrayList<Utilisateur> Users){
  4.          Utilisateur u1;
  5.          ArrayList<Utilisateur> sorted=new ArrayList<>();
  6.          int min,cpt;        
  7.          
  8.          for(int i=0;i<Users.size();i++){
  9.              cpt=0;
  10.              min=Users.get(i).getBackoff();
  11.              for(int j=i;j<Users.size();j++){
  12.                  if(Users.get(j).getBackoff()<min)
  13.                  {
  14.                      min=Users.get(j).getBackoff();
  15.                      cpt=j;
  16.                  }
  17.              }
  18.              sorted.add(Users.get(cpt));
  19.              Users.remove(cpt);
  20.              i--;
  21.          }
  22.         return sorted;
  23.          
  24.      }
  25.   public static void main(String[] args) {
  26.     ArrayList<Utilisateur> users = new ArrayList<Utilisateur>();
  27.     Utilisateur u1 = new Utilisateur();
  28.     Utilisateur u2 = new Utilisateur();
  29.     Utilisateur u3 = new Utilisateur();
  30.     Utilisateur u4 = new Utilisateur();
  31.     u1.setBackoff(4);
  32.     u2.setBackoff(1);
  33.     u3.setBackoff(5);
  34.     u4.setBackoff(2);
  35.     users.add(u1);
  36.     users.add(u2);
  37.     users.add(u3);
  38.     users.add(u4);
  39.     System.out.println("Before");
  40.     for(int i=0; i<users.size();i++){
  41.       System.out.println(users.get(i).getBackoff());
  42.     }
  43.     System.out.println("After");
  44.     ArrayList<Utilisateur> userss = new ArrayList<>();
  45.     userss=sortRT_Collision(users);
  46.     for(int i=0; i<userss.size();i++){
  47.       System.out.println(userss.get(i).getBackoff());
  48.     }
  49.   }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement