พอดีผมลองคอมพายดูแล้วมันจะรันเลขเรียงกัน 1,2,3,4,5 แต่ผมไม่รู้การทำงานของโค้ดแต่ละบรรทัดเลยขอรบกวนผู้รู้ช่วยแนะนำทีครับ
class Shellsort {
public static void main(String args[]) {
int[] array = new int[] { 3, 2, 5, 4, 1 };
int i1, i, j, increment, temp, number_of_elements = array.length;
/* Shell Sort Program */
for (increment = number_of_elements / 2; increment > 0; increment /= 2)
{
for (i = increment; i < number_of_elements; i++)
{
temp = array
;
for (j = i; j >= increment; j -= increment)
{
if (temp < array[j - increment]) {
array[j] = array[j - increment];
} else {
break;
}
}
array[j] = temp;
}
}
System.out.println("After Sorting:");
for (i1 = 0; i1 < 5; i1++) {
System.out.println(array[i1]);
}
}
}