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 1cb76ac

Browse files
Update arx.java
1 parent 0d3f5b8 commit 1cb76ac

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

‎arx.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
import java.util.Scanner;
22
class Search{
3-
public void linearsearch(n,arr)
3+
public void linearsearch(arr,key)
44
{
5-
for
5+
for(int i=0;i<arr.length;i++)
6+
{
7+
if(arr[i]==key)
8+
{
9+
System.out.println("Element found at Index"+i);
10+
return;
11+
}
12+
}
13+
System.out.println("Element not found in the array");
14+
}
15+
16+
public void Binarysearch(arr,element)
17+
{
18+
while(l<=r)
19+
{
20+
21+
}
622
}
723
}
824
class Main{
925
public static void main(String[] args) {
1026
Scanner sc=new Scanner(System.in);
11-
do{
12-
System.out.println("Enter the size of the array:");
13-
n=sc.nextInt();
14-
int arr[n];
15-
for(int i=1;i,n;i++)
16-
{
17-
arr[i]=sc.nextInt();
18-
}
27+
int n;
28+
int[] arr;
1929
System.out.println("MENU DRIVEN ARRAY SORT- SEARCH PROGRAM");
2030
System.out.println("ALGORITHM - Time Complexity");
2131
System.out.println("1.) Linear Search - O(n)");
@@ -25,15 +35,28 @@ public static void main(String[] args) {
2535
System.out.println("5.) Insertion Sort - O(n^2)");
2636
System.out.println("6.) Merge Sort - O(n logn)");
2737
System.out.println("7.) Radix sort - O(nk)");
28-
29-
int choice;
30-
31-
choice=sc.nextInt();
38+
do{
39+
System.out.println("Enter the size of the array:");
40+
n=sc.nextInt();
41+
arr=new int[n];
42+
System.out.println("Enter"+n+"elements in an array:");
43+
for(int i=1;i,n;i++)
44+
{
45+
arr[i]=sc.nextInt();
46+
}
47+
int choice=sc.nextInt();
48+
Search se = new Search();
3249
switch(choice)
3350
{
3451
case 1:
3552
System.out.println("Searching Algorithm : Linear Search")
36-
53+
System.out.println("Enter the Key to search:");
54+
int key=sc.nextInt();
55+
se.linearSearch(arr,key);
56+
57+
case 2:
58+
System.out.println("Searching Algorithm : Binary Search")
59+
3760

3861
}
3962

0 commit comments

Comments
(0)

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