class SortTest {
public void sort1loop() {
int arr[] = { 5, 1, 7, 3, 9 };
for (int i = 1; i < arr.length; i++) {
if (arr[i] < arr[i - 1]) {
arr[i] = arr[i] + arr[i - 1];
arr[i - 1] = arr[i] - arr[i - 1];
arr[i] = arr[i] - arr[i - 1];
i = 0;
}
printArr(arr);
}
System.out.print("Sorted Array : ");
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
No comments:
Post a Comment