Quicksort em ordem descrescente

1 resposta
B

E ae galera, blza?

To tentando implementar um quicksort que ordena em ordem descrescente. Eu fiz algumas mudanças mas não sei se é suficiente . A mudança feita foi na linha 13, onde troquei o <= por >=.
Deem sugestoes ae!

public void quicksort&#40;int p, int q, int array&#91;&#93;&#41;&#123;
        if &#40;p &lt; q&#41;&#123;
            int x = particao&#40;p, q, array&#41;;
            quicksort&#40;p, x - 1, array&#41;;
            quicksort&#40;x + 1, q, array&#41;;
        &#125;
    &#125;
  
    public int particao&#40;int p, int q, int array&#91;&#93;&#41;&#123;
        int j = p - 1;
        int aux = array&#91;q&#93;;
        for &#40;int i = p; i &lt;= q; i++&#41;&#123;
            if &#40;array&#91;i&#93; &gt;= aux&#41;;
            troca&#40;array, i, ++j&#41;;
        &#125;
        return j;
    &#125;
    
    public void troca&#40;int array&#91;&#93;, int i, int j&#41;&#123;
        int aux = array&#91;i&#93;;
        array&#91;i&#93; = array&#91;j&#93;;
        array&#91;j&#93; = aux;
    &#125;

Valeu[/code]

1 Resposta

B

Ninguem?

Criado 16 de fevereiro de 2007
Ultima resposta 21 de fev. de 2007
Respostas 1
Participantes 1