We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
FEAT
1 parent ec24ad9 commit e737dc5Copy full SHA for e737dc5
src/PracticeAlgorithms.java
@@ -164,6 +164,19 @@ private static int rank(int key, int[] array, int minIndex, int maxIndex) {
164
return rank(key, array, minIndex, maxIndex - 1);
165
}
166
167
+ /**
168
+ * static method to brute force search for a "key" in an int array
169
+ * */
170
+ public static int bruteForceSearch(int key, int[] theArray) {
171
+ for (int i = 0; i < theArray.length; i++) {
172
+ if (theArray[i] == key) {
173
+ return i;
174
+ }
175
176
+
177
+ return -1;
178
179
180
181
public static void main(String[] args) {
182
Random generator = new Random();
@@ -247,5 +260,8 @@ public static void main(String[] args) {
247
260
System.out.println("index: " + binarySearch(5, testIntArray));
248
261
System.out.println();
249
262
263
+ System.out.println("- Brute Force Search: key = 3");
264
+ System.out.println("index: " + bruteForceSearch(3, testIntArray));
265
+ System.out.println();
250
266
251
267
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments