JavaScript bubble Sort and select sort

Source: Internet
Author: User

varArray = [1,2,3,4,5];//---> Services//Efficiency---> Highest efficiency for an ordered array//Flag true False for(varj = 0; J < array.length-1;j++ ){    //-J Reduce the number of comparisons after each sort is completed    varIsTrue =true;//if the array itself is ascending, the direct output     for(vari = 0; I < array.length-j-1;i++){        if(Array[i] > array[i+1])        {            vartemp =Array[i]; Array[i]= Array[i+1]; Array[i+1] =temp; IsTrue=false;    }} document.write (array); if(isTrue) { Break; }}
varArray = [12,34,4,6,20];//length-1 j = 0-length-1 for(varj = 0; J < array.length-1;j++){    varmin = Array[j];//1 3 4 345 5    varMinindex =J;  for(vari = j + 1; I < array.length;i++){        if(Array[i] <min) {min=Array[i]; Minindex=i; }    }        if(Minindex! =j) {        vartemp =Array[minindex]; Array[minindex]=Array[j]; ARRAY[J]=temp; }}

JavaScript bubble Sort and select sort

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.