|
@@ -3,13 +3,13 @@
|
3
|
3
|
Problem: Given an array arr[] of n elements, write a function to search a given element x in arr[].
|
4
|
4
|
|
5
|
5
|
```
|
6
|
|
-Input : arr[] = {10, 20, 80, 30, 60, 50,
|
|
6
|
+Input : arr[] = {10, 20, 80, 30, 60, 50,
|
7
|
7
|
110, 100, 130, 170}
|
8
|
8
|
x = 110;
|
9
|
9
|
Output : 6
|
10
|
10
|
Element x is present at index 6
|
11
|
11
|
|
12
|
|
-Input : arr[] = {10, 20, 80, 30, 60, 50,
|
|
12
|
+Input : arr[] = {10, 20, 80, 30, 60, 50,
|
13
|
13
|
110, 100, 130, 170}
|
14
|
14
|
x = 175;
|
15
|
15
|
Output : -1
|
|
@@ -17,6 +17,14 @@ Element x is not present in arr[].
|
17
|
17
|
```
|
18
|
18
|
Hint: linear search
|
19
|
19
|
|
|
20
|
+
|
|
21
|
+*/ Trinh's Solution
|
|
22
|
+I can use a for loop to search each index (i) of the array, using a variable
|
|
23
|
+to store the previous (or first index) to compare to...
|
|
24
|
+using if == ?, if true, return the index (i), if false,
|
|
25
|
+continue searching.
|
|
26
|
+/*
|
|
27
|
+
|
20
|
28
|
### Problem 2
|
21
|
29
|
Problem: Write a Java program to arrange the elements of an given array of integers where all negative integers appear before all the positive integers.
|
22
|
30
|
|
|
@@ -24,4 +32,22 @@ Input:
|
24
|
32
|
`{ 2, 5, -55, 8, -72, -1, 53 }`
|
25
|
33
|
|
26
|
34
|
Output:
|
27
|
|
-`{ -55, -72, -1, 2, 5, 8, 53 }`
|
|
35
|
+`{ -55, -72, -1, 2, 5, 8, 53 }`
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+*/ Trinh's Solution
|
|
39
|
+Nested for loop to bubble sort?
|
|
40
|
+We can start at index 0, and start comparing,
|
|
41
|
+with each pass of the array, it will slowly move the elements
|
|
42
|
+until it becomes sorted.
|
|
43
|
+
|
|
44
|
+If we simply wanted the negative before the positive, we might not need
|
|
45
|
+a nested for loop? Since we aren't checking for < or >
|
|
46
|
+but rather just if it's positive or negative?
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+/*
|