Movatterモバイル変換


[0]ホーム

URL:


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

Commit1cb76ac

Browse files
authored
Update arx.java
1 parent0d3f5b8 commit1cb76ac

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
importjava.util.Scanner;
22
classSearch{
3-
publicvoidlinearsearch(n,arr)
3+
publicvoidlinearsearch(arr,key)
44
{
5-
for
5+
for(inti=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+
publicvoidBinarysearch(arr,element)
17+
{
18+
while(l<=r)
19+
{
20+
21+
}
622
}
723
}
824
classMain{
925
publicstaticvoidmain(String[]args) {
1026
Scannersc=newScanner(System.in);
11-
do{
12-
System.out.println("Enter the size of the array:");
13-
n=sc.nextInt();
14-
intarr[n];
15-
for(inti=1;i,n;i++)
16-
{
17-
arr[i]=sc.nextInt();
18-
}
27+
intn;
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-
intchoice;
30-
31-
choice=sc.nextInt();
38+
do{
39+
System.out.println("Enter the size of the array:");
40+
n=sc.nextInt();
41+
arr=newint[n];
42+
System.out.println("Enter"+n+"elements in an array:");
43+
for(inti=1;i,n;i++)
44+
{
45+
arr[i]=sc.nextInt();
46+
}
47+
intchoice=sc.nextInt();
48+
Searchse =newSearch();
3249
switch(choice)
3350
{
3451
case1:
3552
System.out.println("Searching Algorithm : Linear Search")
36-
53+
System.out.println("Enter the Key to search:");
54+
intkey=sc.nextInt();
55+
se.linearSearch(arr,key);
56+
57+
case2:
58+
System.out.println("Searching Algorithm : Binary Search")
59+
3760

3861
}
3962

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp