Please help me write a code for the sorting algorithm

Answer: // Bubble sort algorithm int[] array = {5, 2, 7, 1, 4};

for (int i = 0; i < array.length - 1; i++) { for (int j = 0; j < array.length - i - 1; j++) { if (array[j] > array[j + 1]) { int temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; }

Guess you like

Origin blog.csdn.net/weixin_35752233/article/details/129518008