mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-11 06:04:27 +08:00
Added Ternary Search
This commit is contained in:
@ -57,7 +57,7 @@ public class TernarySearch{
|
|||||||
System.out.println("Enter number of elements in the array");
|
System.out.println("Enter number of elements in the array");
|
||||||
int n = s.nextInt();
|
int n = s.nextInt();
|
||||||
int arr[] = new int[n];
|
int arr[] = new int[n];
|
||||||
System.out.println("Enter the elements of the array");
|
System.out.println("Enter the elements of the Sorted array");
|
||||||
for (int i= 0; i < n; i++){
|
for (int i= 0; i < n; i++){
|
||||||
arr[i] = s.nextInt();
|
arr[i] = s.nextInt();
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class TernarySearch{
|
|||||||
System.out.println(" The element is not present in the array.");
|
System.out.println(" The element is not present in the array.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("The element is present at the position" + ans);
|
System.out.println("The element is present at the position " + (ans+1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user