X Tutup
Skip to content

Commit f8542e4

Browse files
authored
Updated CombSort.java
As requested done the changes.
1 parent 07015c1 commit f8542e4

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Sorts/CombSort.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
class CombSort
44
{
55
// To find gap between elements
6-
int getNextGap(int gap)
6+
static int getNextGap(int gap)
77
{
88
// Shrink gap by Shrink factor
99
gap = (gap*10)/13;
10-
if (gap < 1)
11-
return 1;
12-
return gap;
10+
gap = (gap < 1) ? 1: gap;
1311
}
1412

1513
// Function to sort arr[] using Comb Sort
16-
void sort(int arr[])
14+
static void sort(int arr[])
1715
{
1816
int n = arr.length;
1917

@@ -24,7 +22,7 @@ void sort(int arr[])
2422
boolean swapped = true;
2523

2624
// Keep running while gap is more than 1 and last iteration caused a swap
27-
while (gap != 1 || swapped == true)
25+
while (gap != 1 || swapped)
2826
{
2927
// Find next gap
3028
gap = getNextGap(gap);
@@ -57,8 +55,8 @@ public static void main(String args[])
5755
ob.sort(arr);
5856

5957
System.out.println("sorted array");
60-
for (int i=0; i<arr.length; ++i)
58+
for (int i=0; i<arr.length; ++i) {
6159
System.out.print(arr[i] + " ");
62-
60+
}
6361
}
6462
}

0 commit comments

Comments
 (0)
X Tutup