Created
October 18, 2018 04:59
-
-
Save uladzislau-slk/8413e38ea4fdb8a714dee7bc915e49f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShakerSort { | |
public static void main(String[] args) { | |
int num[] = {123, -14, 324, -98, 101023, 0, -944, 708}; | |
int buf; | |
System.out.println("Исходный массив: "); | |
for (int i = 0; i < num.length; i++) System.out.print(" " + num[i]); | |
for (int c = 1; c < num.length; c++) { | |
for (int p = 0; p < num.length - 1; p++) { | |
if (num[p] > num[p+1]) { | |
buf = num[p]; | |
num[p] = num[p+1]; | |
num[p+1] = buf; | |
} | |
} | |
for (int n = num.length - 1; n > 0; n--) { | |
if (num[n-1] > num[n]) { | |
buf = num[n-1]; | |
num[n-1] = num[n]; | |
num[n] = buf; | |
} | |
} | |
} | |
System.out.println("\nОтсортированный массив: "); | |
for (int i = 0; i < num.length; i++) System.out.print(" " + num[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment