Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Last active July 11, 2021 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shameemreza/7cf98d7cd6460b5f0563b2a8309ba5ee to your computer and use it in GitHub Desktop.
Save shameemreza/7cf98d7cd6460b5f0563b2a8309ba5ee to your computer and use it in GitHub Desktop.
Step 1 − Set MIN to location 0
Step 2 − Search the minimum element in the list
Step 3 − Swap with value at location MIN
Step 4 − Increment MIN to point to next element
Step 5 − Repeat until list is sorted
@ummulqura12
Copy link

public class LFC {
public static void main(String args[]){
int arr[] = {6, 7, 2, 1, 4};
int size = arr.length;
for (int i = 0 ;i< size-1; i++){
int min = i;
for (int j = i+1; j< size; j++){
if (arr[j] < arr[min]){
min = j;
}
}
int temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
for (int i = 0 ;i< size; i++){
System.out.print(" "+arr[i]);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment