Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

///////////////////Best Bubble Sort /Section sort C++ code from animation ////////////////

int b[5]={15,5,10,20,7};

int temp;

int n=5;

for(int i=0;i<n-1;i++)

cout<<"inside n is "<<n<<endl;

for(int r=0;r<n-1-i;r++)

if(b[r]>b[r+1])

temp=b[r];

b[r]=b[r+1];

b[r+1]=temp;

}//end of inner for

}//end of outer for

cout<<"------sorted array in ascending order-------"<<endl;

for(int j=0;j<n;j++)

cout<<b[j]<<endl;
}

cout<<"------sorted array in descending order-------"<<endl;

for(int k=4;k>=0;k--)

cout<<b[k]<<endl;

You might also like