-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySort.java
50 lines (46 loc) · 1.03 KB
/
MySort.java
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
45
46
47
48
49
50
import java.util.*;
public class MySort
{
ArrayList<SearchResult> sortThisList(MySet<SearchResult> listOfSortableEntries)
{
MySet<SearchResult> tmp=listOfSortableEntries;
tmp.aset.ptr=tmp.aset.head;
ArrayList<SearchResult> sortedList=new ArrayList<SearchResult>();
while(tmp.aset.ptr.next!=null)
{
tmp.aset.ptr=tmp.aset.ptr.next;
sortedList.add(tmp.aset.ptr.data);
}
Comparator<SearchResult> comp=Collections.reverseOrder();
sortingAlgorithm(sortedList,0,sortedList.size()-1,comp);
return sortedList;
}
<X> void sortingAlgorithm(ArrayList<X> arr,int low,int high,Comparator<X> imp)
{
if(low>=high)
return;
if(low<high)
{
X pivot=arr.get(high);
int i=low-1;
int j=0;
X temp;
for(j=low;j<high;j++)
{
if(imp.compare(arr.get(j),pivot)<=0)
{
i++;
temp=arr.get(i);
arr.set(i,arr.get(j));
arr.set(j,temp);
}
}
temp=arr.get(i+1);
arr.set(i+1,arr.get(high));
arr.set(high,temp);
int p=i+1;
sortingAlgorithm(arr,low,p-1,imp);
sortingAlgorithm(arr,p+1,high,imp);
}
}
}