본문 바로가기

Algorithm

정렬

반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package test;
 
 
public class test {
    public static class Chemi implements Comparable<Chemi>{
        int x;
        int y;
        public Chemi(int x, int y) {
            super();
            this.x = x;
            this.y = y;
        }
        @Override
        public int compareTo(Chemi o) {
            // TODO Auto-generated method stub
            if(this.y >o.y) {
                return 1;
            }
            else{
                return -1;
            }
        }
        
    }
    
    public static void main(String[] args) {
        Chemi chemi[] = new Chemi[4];
        
        
        chemi[0= new Chemi(-105);
        chemi[1= new Chemi(125755);
        chemi[2= new Chemi(7657653);
        chemi[3= new Chemi(-12344);
        
        Arrays.sort(chemi);
        
        for(int i=0;i<4;i++) {
            System.out.println(chemi[i].x +" "+chemi[i].y);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
반응형