Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f39a76a

Browse files
linear search within range program added
1 parent 4fdaa71 commit f39a76a

11 files changed

+154
-58
lines changed

‎Linear Search/DSAlinearSearch.class

-1.09 KB
Binary file not shown.

‎Linear Search/DSAlinearSearch.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎Linear Search/FinalLinearSearch.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class FinalLinearSearch {
2+
3+
public static void main(String[] args){
4+
int[] array = {12, 45, 3, 65, 23, 78, 90, 43};
5+
int target = 100;
6+
int answer = linearsearch(array, target);
7+
System.out.println(answer);
8+
9+
}
10+
public static int linearsearch(int[] searcharray, int target){
11+
if (searcharray.length ==0) {
12+
System.out.println("nothing exists");
13+
14+
}
15+
for(int index=0; index < searcharray.length; index++){
16+
if (target == searcharray[index]) {
17+
System.out.println(index);
18+
return target;
19+
20+
}
21+
}
22+
System.out.println("doesnot exists");
23+
return Integer.MAX_VALUE;
24+
}
25+
26+
}

‎Linear Search/LinearSearchString.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// public class LinearSearchString {
2+
// public static void main(String[] args) {
3+
// String name = "SumanPaik";
4+
// char target = 'P';
5+
// // System.out.println(name.length());
6+
// // System.out.println(name.length() );
7+
// // System.out.println(name.charAt(2));
8+
// boolean ans = stringLinearSearch(name, target);
9+
// System.out.println(ans);
10+
// }
11+
12+
// public static boolean stringLinearSearch(String str, char target){
13+
// if (str.length() == 0) {
14+
// return false;
15+
16+
// }
17+
// for (int i = 0; i < str.length(); i++) {
18+
19+
// if (target == str.charAt(i)) {
20+
// return true;
21+
// }
22+
// }
23+
// return false;
24+
// }
25+
// }
26+
27+
28+
29+
public class LinearSearchString {
30+
31+
public static void main(String[] args) {
32+
String name = "LinearSearch";
33+
char target = 'S';
34+
boolean ans = SearchLinear(name, target);
35+
System.out.println(ans);
36+
}
37+
38+
public static boolean SearchLinear(String str, char target){
39+
if (str.length() == 0) {
40+
return false;
41+
42+
}
43+
for (int i = 0; i < str.length(); i++) {
44+
if (target == str.charAt(i)) {
45+
return true;
46+
47+
}
48+
49+
}
50+
return false;
51+
}
52+
53+
}
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+

‎Linear Search/Linearsearch.class

-659 Bytes
Binary file not shown.

‎Linear Search/Linearsearch.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
public class Linearsearch {
2-
3-
static void linearelement( int[] arr, int key ){
4-
for (int i = 0; i < arr.length; i++) {
5-
if (arr[i] == key) {
6-
System.out.println(arr[i]);
7-
continue;
8-
}
9-
else{
10-
System.out.println("Not Found");
1+
public class Linearsearch{
2+
public static void main(String[] args){
3+
int[] arraycollection = {12, 34, 56, 78, 32, 54, 76, 89, 33, 55, 44, 22, 99};
4+
int target = 99;
5+
int answer = linearsearchalgo(arraycollection, target);
6+
System.out.print(answer); // output : 12
7+
}
8+
9+
// linear search function
10+
public static int linearsearchalgo(int[] array, int target){
11+
if(array.length == 0){
12+
System.out.println("Array does not exists");
13+
}
14+
for (int index = 0; index < array.length; index++) {
15+
if (target == array[index]) {
16+
return index;
17+
1118
}
1219
}
20+
return Integer.MAX_VALUE;
1321

1422
}
15-
public static void main(String[] args) {
16-
int[] arr = {12, 23, 45, 67, 43 ,98};
17-
int key = 45;
18-
19-
linearelement(arr, key);
20-
2123

22-
}
23-
}
24+
}

‎Linear Search/RangeLinearSearchArray.java

Whitespace-only changes.
-1.14 KB
Binary file not shown.

‎Linear Search/tempCodeRunnerFile.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class LinearSearchString {
2+
// public static void main(String[] args) {
3+
// String name = "SumanPaik";
4+
// char target = 'P';
5+
// // System.out.println(name.length());
6+
// // System.out.println(name.length() );
7+
// // System.out.println(name.charAt(2));
8+
// boolean ans = stringLinearSearch(name, target);
9+
// System.out.println(ans);
10+
// }
11+
12+
// public static boolean stringLinearSearch(String str, char target){
13+
// if (str.length() == 0) {
14+
// return false;
15+
16+
// }
17+
// for (int i = 0; i < str.length(); i++) {
18+
19+
// if (target == str.charAt(i)) {
20+
// return true;
21+
// }
22+
// }
23+
// return false;
24+
// }
25+
// }

‎Linear Search/yt.class

-497 Bytes
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /