fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class CompInt{
  6. int comp(Integer i1, Integer i2){
  7. return i1 - i2;
  8. }
  9. }
  10. class MyCollections{
  11. static void mysort(List ls, CompInt compInt){
  12. for(int i=0; i<ls.size(); i++){
  13. for(int j=i+1; j<ls.size(); j++){
  14. if(compInt.comp((Integer)ls.get(i), (Integer)ls.get(j)) < 0){
  15. Integer temp = (Integer)ls.get(i);
  16. ls.set(i, ls.get(j));
  17. ls.set(j, temp);
  18. }
  19. }
  20. }
  21. }
  22. }
  23.  
  24. class Ideone{
  25. public static void main (String[] args) throws java.lang.Exception{
  26. List ls = new ArrayList<>(Arrays.asList(30,55,20,15,40));
  27. MyCollections.mysort(ls, new CompInt());
  28.  
  29. for(Object x: ls){
  30. System.out.println((Integer)x);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.08s 42588KB
stdin
Standard input is empty
stdout
55
40
30
20
15