import
java.util.*;
class
GFG
{
static
int
partition(Vector<String> objects,
int
l,
int
r,
Map<String, Integer> hash)
{
int
j = l -
1
;
int
last_element = hash.get(objects.get(r));
for
(
int
i = l; i < r; i++)
{
if
(hash.get(objects.get(i)) <= last_element)
{
j++;
Collections.swap(objects, i, j);
}
}
j++;
Collections.swap(objects, j, r);
return
j;
}
static
void
quicksort(Vector<String> objects,
int
l,
int
r,
Map<String, Integer> hash)
{
if
(l < r)
{
int
mid = partition(objects, l, r, hash);
quicksort(objects, l, mid -
1
, hash);
quicksort(objects, mid +
1
, r, hash);
}
}
static
void
sortObj(Vector<String> objects)
{
Map<String, Integer> hash =
new
HashMap<>();
hash. put(
"blue"
,
1
);
hash. put(
"red"
,
2
);
hash. put(
"yellow"
,
3
);
quicksort(objects,
0
, objects.size() -
1
, hash);
for
(
int
i =
0
; i < objects.size(); i++)
System.out.print(objects.get(i) +
" "
);
}
public
static
void
main(String []args)
{
Vector<String> objects =
new
Vector<>(Arrays.asList(
"red"
,
"blue"
,
"red"
,
"yellow"
,
"blue"
));
sortObj(objects);
}
}