Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Java - Collection to keep the best results

I have a list of 2D points (a custom Node class). I would like to pick a Node and say "Ehy, the 10 closest node in my list are those ten"

Now, what's the problem: I would like to make something like:

ArrayList<Node> nodes; //list of nodes
            ArrayList<Node> topten; //list of nearest nodes
            Node currentNode; //the current point
            for (Node x : nodes){
                if (x.distance(currentNode) < (topten.THE_FURTHER_POINT()).distance(currentNode))
                    topten.ADD(x);

            }

I would like to know if there is already a Collection which have those pseudo-methods (THE_FURTHER_POINT and ADD) Those two methods should work like this:

THE_FURTHER_POINT: return the further point. The collection should be fixed-length, so this method should always return the last element (if I have 8 elements inside the topten, i should receive the node with index 7, if I have 10 elements I should receive the node with index 9)

ADD: everytime an elements is added, if the collection is full the latest elements get eliminated. The collection should be always ordinate, and this operation should be as quick as possibile (if I have 8 elements in the topten, I will end up with 9 elements after the add. if I have 10 elements, I will end up with 10 elements after the add)

Thank you a lot!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In the end, what i really was searching for was a collection

  • ALWAYS SORTED
  • WITH FIXED LENGTH

So... After reading Java PriorityQueue with fixed size I think I found my reply. This can be considered a duplicate question.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda