First Experiment in Oops Lab
First Experiment in Oops Lab
Program:Sequential search
import java.util.Scanner;
if (arr[i] == target)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
arr[i] = scanner.nextInt();
if (index != -1)
else
{
System.out.println("Target " + target + " not found in the array");
scanner.close();
import java.util.Arrays;
import java.util.Scanner;
int left = 0;
if (arr[mid] == target) {
} else {
}
}
// Input array size and elements (assuming array is sorted for binary search)
int n = scanner.nextInt();
arr[i] = scanner.nextInt();
if (index != -1) {
} else {
System.out.println("Target " + target + " not found in the array");
scanner.close();
import java.util.Arrays;
import java.util.Scanner;
int n = arr.length;
int minIndex = i;
minIndex = j;
// Swap the found minimum element with the first element of the
unsorted part
arr[minIndex] = arr[i];
arr[i] = temp;
int n = scanner.nextInt();
arr[i] = scanner.nextInt();
selectionSort(arr);
scanner.close();
}
Insertion Sort with User Input:
import java.util.Arrays;
import java.util.Scanner;
int n = arr.length;
int j = i - 1;
arr[j + 1] = arr[j];
j--;
arr[j + 1] = key;
arr[i] = scanner.nextInt();
insertionSort(arr);
scanner.close();