/*
Selection Sort is a Basic Sorting
Algorithm
Based On Comparison of elements.
Time Complexity O(n²)
Exponential Time.
Because We Compare Each N elements
In N Single Elements and Swap Them.
*/
class selectionSort{
public static void main(String[] args){
int[] arr={8,7,6,1,2,4};
int n=arr.length;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(arr[i]>arr[j]){
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0;i<n;i++){
System.out.println(Rand(10));
}
}
}
Comments
Post a Comment