Created
July 23, 2019 20:30
-
-
Save anthony17guty/a1d19e12a4ecb39f130ddb8c2984872e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!doctype html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<h1>Metodo burbuja en JavaScript</h1> | |
<script> | |
function burbuja(miArray) | |
{ | |
for(var i=1;i<miArray.length;i++) | |
{ | |
for(var j=0;j<(miArray.length-i);j++) | |
{ | |
if(miArray[j]>miArray[j+1]) | |
{ | |
k=miArray[j+1]; | |
miArray[j+1]=miArray[j]; | |
miArray[j]=k; | |
} | |
} | |
} | |
return miArray; | |
} | |
miArray=Array(59, 64, 82, 28, 1, 93, 52, 29, 19, 46, 40, 80, 53, 71, 78, 61, 38, 20, 54, 34, 86, 47, 75, 25, 31, | |
39, 43, 69, 92, 10, 68, 98, 84, 72, 99, 87, 21, 24, 91, 13, 8, 44, 9, 16, 94, 95, 7, 62, 63, 42, 15, 23, 51, 57, | |
97, 77, 32, 50, 79, 12, 14, 58, 4, 22, 81, 17, 3, 60, 83, 35, 90, 55, 26, 2, 56, 67, 74, 70, 66, 5, 76, 100, 36, | |
18, 89, 65, 27, 41, 30, 33, 88, 73, 6, 45, 96, 48, 85, 49, 11, 37); | |
document.write("Valores Iniciales<br>"); | |
for(var i=0;i<miArray.length;i++) | |
{ | |
document.write(miArray[i]+"<br>"); | |
} | |
arrayB=burbuja(miArray); | |
document.write("Valores ordenados<br>"); | |
for(i=0;i<arrayB.length;i++) | |
{ | |
document.write(arrayB[i]+"<br>"); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment