I have a file loaded with 300,000 thousand prices. I need to put the prices in ascending order in a list. If I put it in standard mode, analyzing linearly where to enter each price, my algorithm gets very slow. Does anyone have an idea of a quick way to do this?
EDIT:
These are random prices that I need to sort.
19.5, 11.3, 17.43, 1.32, 36.45, etc.
I'm doing a contextualization because what I really want to do is a bit different but requires knowledge of my system. This is an abstraction.
EDIT. 2:
if (Type == 0) {
for (int i = 0; i < Objeto.size(); i++) {
//Ordena pelo menor preço. Se o primeiro elemento tiver preço menor que algum da lista completa,
//tal elemento é inserido anterior a esse algum
if (PrimeiroElemento.getPrice() > Objeto.get(i).getPrice()) {
return i;
}
if (PrimeiroElemento.getPrice() == Objeto.get(i).getPrice()) {
//se os preços forem iguais, ordena pelo tempo
if (PrimeiroElemento.getTimestamp() < Objeto.get(i).getTimestamp()) {
return i;
}
}
}