Created
September 20, 2015 22:25
-
-
Save cristianmiranda/72230656cea39e98a2b4 to your computer and use it in GitHub Desktop.
Insersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.unlam.impl; | |
import edu.unlam.Ordenadora; | |
public class Insersion extends Ordenadora { | |
@Override | |
public void sort(Comparable[] elements) { | |
int n = elements.length; | |
for (int i = 0; i < n; i++) { | |
for (int j = i; j > 0 && elements[j].compareTo(elements[j - 1]) < 0; j--) { | |
exch(elements, j, j - 1); | |
} | |
assert isSorted(elements, 0, i); | |
} | |
assert isSorted(elements); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment