Changes in for loop for sorting

This would decrease the number of comparisons in the loop used for sorting.
This commit is contained in:
Shubhk15
2017-04-01 23:42:34 +05:30
committed by GitHub
parent 8c38c60b93
commit fc9e3f6196

View File

@ -15,15 +15,15 @@ class BubbleSort
}
//Sorting
for(int i=0; i<6; i++)
for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
for(int j=i+1; j<6; j++)
{
if(array[j]>array[j+1])
if(array[j]>array[i])
{
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
array[j]=array[i];
array[i]=temp;
}
}
}
@ -35,4 +35,4 @@ class BubbleSort
}
}
}
}