Friday, 10 June 2022

SelectionSort

 import java.util.Arrays;
//Bubble sort 
public class Example4 {
public static void main(String[] args) {
int arr[] = { 10, 40, 4, 60, 5, 1 };
// 10,4,40,5,1,60
// bubbleSort(arr);
selectionSortMax(arr);
System.out.println(Arrays.toString(arr));
}

public static void selectionSort(int[] input) {
for (int i = 0; i < input.length ; i++) {

int minIndex = i;
for (int j = i + 1; j < input.length; j++) {
if (input[j] < input[minIndex]) {
minIndex = j;
}
}
int temp = input[minIndex];
input[minIndex] = input[i];
input[i] = temp;
}
}



// Need to write code with maximum to minimum

public static void selectionSortMax(int[] input) {
for (int i = 0; i < input.length ; i++) {

int maxIndex = input.length-1-i;
for (int j = input.length-2-i; j >= 0; j--) {
if (input[j] > input[maxIndex]) {
maxIndex = j;
}
}
int temp = input[maxIndex];
input[maxIndex] = input[input.length-1-i];
input[input.length-1-i] = temp;
}
}
//10, 40, 4, 60, 5, 1



}

Wednesday, 8 June 2022

Bubble Sort

 import java.util.Arrays;
public class Example4 {
public static void main(String[] args) {
int arr[] = { 10, 40, 4, 60, 5, 1 };

//10,4,40,5,1,60


bubbleSort(arr);

System.out.println(Arrays.toString(arr));
}

for(int j=0;j<input.length;j++)
{

for(int i=0;i<input.length-j-1;i++)
{
if(input[i]>input[i+1])
{
int temp=input[i];
input[i]=input[i+1];
input[i+1]=temp;

}
}
}
}



}


06/20/024 ( TODO)

Q1 : Create array , add element ,remove element , and update the element  Q2: Show me how overloading and overriding work in inheritance wit...