Heap Sort

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Heap Sort as PDF for free.

More details

  • Words: 162
  • Pages: 1
package br.edu.unicapital.Ordenacao; public class Heap { private int numeros []; public void setNumeros (int [] vetor) { // capitura o vetor a ordenar numeros = vetor; } private int [] getNumeros () { return numeros; } public int[] ordene () { // metodo que retorna o vetor ordenado heapSort(getNumeros()); System.out.println("Valores ordenados pelo Heap: "); return getNumeros(); } private

}

int n = v.length; for (int i = v.length - 1; i > 0; i--) { swap(v, i, 0); ordenando(v, 0, --n); }

private

}

void heapSort(int v[]) {

void ordenando(int v[], int pos, int n) {

int max = 2 * pos + 1, right = max + 1; if (max < n) { if (right < n && v[max] < v[right]) max = right; if (v[max] > v[pos]) { swap(v, max, pos); ordenando(v, max, n); } }

private void swap(int[] v, int j, int aposJ) { int aux = 0; aux = v[j]; v[j] = v[aposJ]; v[aposJ] = aux; } }

Related Documents

Heap Sort
May 2020 9
Heap Sort
April 2020 24
Heap Sort
November 2019 15
L09 Heap Tree & Sort
July 2020 5
Heap
May 2020 9
Sort
November 2019 21