5
5
public class BogoSort {
6
6
7
7
/**
8
- * @param vetor
8
+ * @param vector
9
9
*/
10
- public int [] sort (int [] vetor ) {
11
- // Verifica se o vetor está ordenado
12
- while (!isSorted (vetor )) {
13
- // Embaralha o vetor pra tentar ordenar aleatoriamente
14
- shuffle (vetor );
10
+ public int [] sort (int [] vector ) {
11
+ // Checking if the vector is ordered
12
+ while (!isSorted (vector )) {
13
+ // Shuffle the vector to try to sort it randomly
14
+ shuffle (vector );
15
15
}
16
- return vetor ;
16
+ return vector ;
17
17
}
18
18
19
19
/**
20
- * Verifica se o vetor está ordenado
20
+ * Checking again if the vector is ordered
21
21
*
22
- * @param vetor
22
+ * @param vector
23
23
* @return
24
24
*/
25
- private static boolean isSorted (int [] vetor ) {
26
- for (int i = 0 ; i < (vetor .length - 1 ); ++i ) {
27
- if (vetor [i ] > vetor [i + 1 ]) {
25
+ private static boolean isSorted (int [] vector ) {
26
+ for (int i = 0 ; i < (vector .length - 1 ); ++i ) {
27
+ if (vector [i ] > vector [i + 1 ]) {
28
28
return false ;
29
29
}
30
30
}
@@ -33,17 +33,17 @@ private static boolean isSorted(int[] vetor) {
33
33
}
34
34
35
35
/**
36
- * Embaralha o vetor pra tentar ordenar aleatoriamente
36
+ * Shuffle the vector to try to sort it randomly
37
37
*
38
- * @param vetor Vetor a ser ordenado
38
+ * @param vector Vector is to be sorted
39
39
*/
40
- private static void shuffle (int [] vetor ) {
41
- for (int x = 0 ; x < vetor .length ; ++x ) {
42
- int index1 = (int ) (Math .random () * vetor .length ),
43
- index2 = (int ) (Math .random () * vetor .length );
44
- int a = vetor [index1 ];
45
- vetor [index1 ] = vetor [index2 ];
46
- vetor [index2 ] = a ;
40
+ private static void shuffle (int [] vector ) {
41
+ for (int x = 0 ; x < vector .length ; ++x ) {
42
+ int index1 = (int ) (Math .random () * vector .length ),
43
+ index2 = (int ) (Math .random () * vector .length );
44
+ int a = vector [index1 ];
45
+ vector [index1 ] = vector [index2 ];
46
+ vector [index2 ] = a ;
47
47
}
48
48
}
49
49
}
@@ -54,26 +54,26 @@ private static void shuffle(int[] vetor) {
54
54
public class BogoSort {
55
55
56
56
/**
57
- * @param vetor
57
+ * @param vector
58
58
*/
59
- public int [] sort (int [] vetor ) {
60
- // Verifica se o vetor está ordenado
61
- while (!isSorted (vetor )) {
62
- // Embaralha o vetor pra tentar ordenar aleatoriamente
63
- shuffle (vetor );
59
+ public int [] sort (int [] vector ) {
60
+ // Verify if the vector is ordered
61
+ while (!isSorted (vector )) {
62
+ // Shuffle the vector to try to sort it randomly
63
+ shuffle (vector );
64
64
}
65
- return vetor ;
65
+ return vector ;
66
66
}
67
67
68
68
/**
69
- * Verifica se o vetor está ordenado
69
+ * Verify if the vector (named vector) is sorted
70
70
*
71
- * @param vetor
71
+ * @param vector
72
72
* @return
73
73
*/
74
- private static boolean isSorted (int [] vetor ) {
75
- for (int i = 0 ; i < (vetor .length - 1 ); ++i ) {
76
- if (vetor [i ] > vetor [i + 1 ]) {
74
+ private static boolean isSorted (int [] vector ) {
75
+ for (int i = 0 ; i < (vector .length - 1 ); ++i ) {
76
+ if (vector [i ] > vector [i + 1 ]) {
77
77
return false ;
78
78
}
79
79
}
@@ -82,17 +82,17 @@ private static boolean isSorted(int[] vetor) {
82
82
}
83
83
84
84
/**
85
- * Embaralha o vetor pra tentar ordenar aleatoriamente
85
+ * Shuffle the vector to try to sort it randomly
86
86
*
87
- * @param vetor Vetor a ser ordenado
87
+ * @param vector Vector is to be sorted
88
88
*/
89
- private static void shuffle (int [] vetor ) {
90
- for (int x = 0 ; x < vetor .length ; ++x ) {
91
- int index1 = (int ) (Math .random () * vetor .length ),
92
- index2 = (int ) (Math .random () * vetor .length );
93
- int a = vetor [index1 ];
94
- vetor [index1 ] = vetor [index2 ];
95
- vetor [index2 ] = a ;
89
+ private static void shuffle (int [] vector ) {
90
+ for (int x = 0 ; x < vector .length ; ++x ) {
91
+ int index1 = (int ) (Math .random () * vector .length ),
92
+ index2 = (int ) (Math .random () * vector .length );
93
+ int a = vector [index1 ];
94
+ vector [index1 ] = vector [index2 ];
95
+ vector [index2 ] = a ;
96
96
}
97
97
}
98
98
}
0 commit comments