Bubble sort of arrays in javascript is used as an example

  • 2020-03-30 00:57:12
  • OfStack

 
<html> 
<head> 
<title> Sort of array </title> 

<script> 
var arr = [2,4,9,11,6,3,88]; 
//Bubble sort, bubble up, minimum at the top
for(var x = 0 ; x < arr.length; x++){//Control the train number
for(var y = x + 1 ; y < arr.length ; y++){ 
//Compare in turn, and swap if the next element is greater than the previous one
if(arr[x] > arr[y]){ 
var temp = arr[x]; 
arr[x] = arr[y]; 
arr[y] = temp; 
} 
} 
} 
document.write(arr); 

</script> 

</head> 

<body> 
<div id="time"></div> 
</body> 

</html> 

Related articles: