Updated CombSort.java

As requested done the changes.
This commit is contained in:
Sandeep Roy 2018-04-05 14:31:51 +05:30 committed by GitHub
parent 07015c1e64
commit f8542e4db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,17 +3,15 @@
class CombSort
{
// To find gap between elements
int getNextGap(int gap)
static int getNextGap(int gap)
{
// Shrink gap by Shrink factor
gap = (gap*10)/13;
if (gap < 1)
return 1;
return gap;
gap = (gap < 1) ? 1: gap;
}
// Function to sort arr[] using Comb Sort
void sort(int arr[])
static void sort(int arr[])
{
int n = arr.length;
@ -24,7 +22,7 @@ class CombSort
boolean swapped = true;
// Keep running while gap is more than 1 and last iteration caused a swap
while (gap != 1 || swapped == true)
while (gap != 1 || swapped)
{
// Find next gap
gap = getNextGap(gap);
@ -57,8 +55,8 @@ class CombSort
ob.sort(arr);
System.out.println("sorted array");
for (int i=0; i<arr.length; ++i)
for (int i=0; i<arr.length; ++i) {
System.out.print(arr[i] + " ");
}
}
}