-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQucikSort.java
More file actions
39 lines (33 loc) · 745 Bytes
/
Copy pathQucikSort.java
File metadata and controls
39 lines (33 loc) · 745 Bytes
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
/**
* @author Andrei Geadau
*The full implementation of QueueList can be found in my other directories
*/
public class QuickSort {
public static void sort(QueueList<Integer> q) {
if(q.size() < 2) {
return;
}
//Divide
int pivot = q.first();
QueueList<Integer> L = new QueueList<>();
QueueList<Integer> E = new QueueList<>();
QueueList<Integer> G = new QueueList<>();
while(!q.isEmpty()) {
int el = q.deque();
if(el<pivot) {
L.enque(el);
}else if(el > pivot) {
G.enque(el);
}else {
E.enque(el);
}
}
//CONQUER
sort(L);
sort(G);
//MERGE
while(!L.isEmpty()) {q.enque(L.deque());}
while(!E.isEmpty()) {q.enque(E.deque());}
while(!G.isEmpty()) {q.enque(G.deque());}
}
}