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

View File

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