Why for this im not getting correct output of elements in increasing?... I wrote the same code as said above in video

public class selection {

public static void main(String[] args) {

	int[] arr = { 88,11 ,44 , 99 ,55};
	selectionsort(arr);

	display(arr);

}

public static void display(int[] arr) {

	for (int val : arr) {
		System.out.println(val);
	}

}

public static void selectionsort(int[] arr) {
	
	for(int counter = 0 ; counter<arr.length-1 ; counter++) {
		
		int min = counter;
		
		for(int i = counter+1 ; i<=arr.length-1 ; i++) {
			
			if(arr[i] < arr[min]) {
				min = i;
			}
			
			int temp = arr[min];
			arr[min] = arr[counter];
			arr[counter] =  temp;
		}
	}
            
	
}

}

hi @LakshmiPrasanna0303 you need to swap after finding the local minimum

import java.util.*;

class temp2 {
public static void main(String[] args) {

	int[] arr = { 88, 11, 44, 99, 55 };
	selectionsort(arr);

	display(arr);

}

public static void display(int[] arr) {

	for (int val : arr) {
		System.out.print(val+" ");
	}

}

public static void selectionsort(int[] arr) {

	for (int counter = 0; counter <= arr.length - 1; counter++) {

		int min = counter;

		for (int i = counter + 1; i <= arr.length - 1; i++) {

			if (arr[i] < arr[min]) {
				min = i;
			}

//int temp = arr[min];
		//arr[min] = arr[counter];
		//arr[counter] = temp;
		
		}
		int temp = arr[min];
		arr[min] = arr[counter];
		arr[counter] = temp;
	}

}

}

i have made few changes if you have any doubt do ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.