summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/UI/UILayerQuickSort.java
blob: 63553474c3703885ccc827a8ea9761ef99112967 (plain)
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
package net.tylermurphy.Minecraft.UI;

import java.util.List;

public class UILayerQuickSort {
 
    public static void quickSort(List<UIComponent> arr, int start, int end){
 
        int partition = partition(UIMaster.componentBatch, start, end);
 
        if(partition-1>start) {
            quickSort(UIMaster.componentBatch, start, partition - 1);
        }
        if(partition+1<end) {
            quickSort(UIMaster.componentBatch, partition + 1, end);
        }
    }
 
    public static int partition(List<UIComponent> arr, int start, int end){
    	
    	UIComponent pivot = arr.get(end);
 
        for(int i=start; i<end; i++){
            if(arr.get(i).getZIndex()<pivot.getZIndex()){
            	UIComponent temp= arr.get(start);
                arr.set(start, arr.get(i));
                arr.set(i, temp);
                start++;
            }
        }
 
        UIComponent temp = arr.get(start);
        arr.set(start, pivot);
        arr.set(end, temp);
 
        return start;
    }
}