Created
September 20, 2015 22:24
-
-
Save cristianmiranda/93cc0d5e93183fccd7f1 to your computer and use it in GitHub Desktop.
Burbuja.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 Burbuja extends Ordenadora { | |
@Override | |
public void sort(Comparable[] elements) { | |
int n = elements.length; | |
for (int i = 0; i < (n - 1); i++) { | |
for (int j = 0; j < n - i - 1; j++) { | |
if (elements[j].compareTo(elements[j + 1]) > 0) { | |
Comparable swap = elements[j]; | |
elements[j] = elements[j + 1]; | |
elements[j + 1] = swap; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment