<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="智能社 - zhinengshe.com"> <meta name="copyright" content="智能社 - zhinengshe.com"> <title>智能社 - www.zhinengshe.com</title> <script> var arr=[88, 12, 5, 3, 99, 22, 4]; for (var i=0; i<arr.length; i++) { var nMinIndex=findMin(arr, i); var tmp=null; tmp=arr[nMinIndex]; arr[nMinIndex]=arr[i]; arr[i]=tmp; } alert(arr); function findMin(arr, start) { var nMin=99999; var nMinIndex=-1; for (var i=start; i<arr.length; i++) { if (arr[i]<nMin) { nMin=arr[i]; nMinIndex=i; } } return nMinIndex; } </script> </head> <body> </body> </html>
时间: 2024-10-23 22:05:18