Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python
C
Java
my_array = [64, 34, 25, 5, 22, 11, 90, 12] n = len(my_array) for i in range(n-1): min_index = i for j in range(i+1, n): if my_array[j] < my_array[min_index]: min_index = j min_value = my_array.pop(min_index) my_array.insert(i, min_value) print("Sorted array:", my_array) #Python
#include
int main() { int my_array[] = {64, 34, 25, 5, 22, 11, 90, 12}; int n = sizeof(my_array) / sizeof(my_array[0]); for (int i = 0; i < n-1; i++) { int min_index = i; for (int j = i+1; j < n; j++) { if (my_array[j] < my_array[min_index]) { min_index = j; } } int min_value = my_array[min_index]; for (int k = min_index; k > i; k--) { my_array[k] = my_array[k-1]; } my_array[i] = min_value; } printf("Sorted array: "); for (int i = 0; i < n; i++) { printf("%d ", my_array[i]); } printf("\n"); return 0; } //C
public class Main { public static void main(String[] args) { int[] my_array = {64, 34, 25, 5, 22, 11, 90, 12}; int n = my_array.length; for (int i = 0; i < n-1; i++) { int min_index = i; for (int j = i+1; j < n; j++) { if (my_array[j] < my_array[min_index]) { min_index = j; } } int min_value = my_array[min_index]; for (int k = min_index; k > i; k--) { my_array[k] = my_array[k-1]; } my_array[i] = min_value; } System.out.print("Sorted array: "); for (int i = 0; i < n; i++) { System.out.print(my_array[i] + " "); } System.out.println(); } } //Java
Python result:
C result:
Java result:
Sorted array: [5, 11, 12, 22, 25, 34, 64, 90]
Sorted array: 5 11 12 22 25 34 64 90
Sorted array: 5 11 12 22 25 34 64 90