Skip to content

Instantly share code, notes, and snippets.

@herquiloidehele
Last active December 13, 2018 15:28
Show Gist options
  • Select an option

  • Save herquiloidehele/d07753ad0b2d9a12054a9e2a5d659cef to your computer and use it in GitHub Desktop.

Select an option

Save herquiloidehele/d07753ad0b2d9a12054a9e2a5d659cef to your computer and use it in GitHub Desktop.
package modelo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Vector;
/**
*
* @author herquiloide
*/
public class OrdenarNumerosArray {
public static void main(String[] args) {
Vector<Integer> v = new Vector(Arrays.asList(12, 8, 6, 10, 23, 14));
System.out.println("K | " + "aux | " + "j | "+ "(j>=0 && v[j] > aux) | " + "v[j+1] = v[j] | "+ "v[j+1] = aux" + " V " );
for (int k = 1; k < v.size(); k++){
int aux = v.get(k);
int j = k - 1;
boolean condicao = j>=0 && v.get(j) > aux;
while(j>=0 && v.get(j) > aux){
v.set(j+1, v.get(j));
System.out.println(k + " " + aux + " "+ j + " "+ condicao+ " " +v.get(j) + " "+ aux + " " + v.toString() );
j = j - 1;
}
v.set(j+1, aux);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment