@@ -94,6 +94,14 @@ public static void printTwoDmIntArray(int[][] theArray) {
94
94
}
95
95
96
96
97
+ public static void printIntArray (int [] theArray ) {
98
+ for (int item : theArray ) {
99
+ System .out .printf ("%d " , item );
100
+ }
101
+ System .out .println ();
102
+ }
103
+
104
+
97
105
/**
98
106
* static method that returns the transposition of an input matrix
99
107
* */
@@ -144,7 +152,7 @@ public static int binarySearch(int key, int[] array) {
144
152
/**
145
153
* static recursive method that implements binary search
146
154
* */
147
- public static int rank (int key , int [] array , int minIndex , int maxIndex ) {
155
+ private static int rank (int key , int [] array , int minIndex , int maxIndex ) {
148
156
if (minIndex > maxIndex ) return -1 ;
149
157
int midIndex = minIndex + (maxIndex - minIndex ) / 2 ;
150
158
@@ -180,6 +188,9 @@ public static void main(String[] args) {
180
188
testIntArray [8 ] = 1 ;
181
189
testIntArray [9 ] = 10 ;
182
190
191
+ int [] sortedTestIntArray = Arrays .copyOf (testIntArray , testIntArray .length );
192
+ Arrays .sort (sortedTestIntArray );
193
+
183
194
testTwoDmBooleanArray [0 ][0 ] = true ;
184
195
testTwoDmBooleanArray [0 ][1 ] = false ;
185
196
testTwoDmBooleanArray [1 ][0 ] = false ;
@@ -228,8 +239,13 @@ public static void main(String[] args) {
228
239
System .out .printf ("31!: %d\n " , fact (31 )); // N > 31 causes overflow
229
240
System .out .println ();
230
241
242
+ System .out .println ("- The Sorted Array" );
243
+ printIntArray (sortedTestIntArray );
244
+ System .out .println ();
245
+
231
246
System .out .println ("- Binary Search: key = 5" );
232
- System .out .println (binarySearch (5 , testIntArray ));
247
+ System .out .println ("index: " + binarySearch (5 , testIntArray ));
233
248
System .out .println ();
249
+
234
250
}
235
251
}
0 commit comments