package main
import (
"fmt"
"math/rand"
"time"
)
// selectionSort sorts an array using the selection sort algorithm.
func selectionSort(arr []int) {
n := len(arr)
for i := 0; i < n-1; i++ {
minIndex := i
for j := i + 1; j < n; j++ {
if arr[j] < arr[minIndex] {
minIndex = j
}
}
// Swap the found minimum element with the first element
arr[i], arr[minIndex] = arr[minIndex], arr[i]
}
}
func main() {
// Seed the random number generator
rand.Seed(time.Now().UnixNano())
// Create an array of 50 random integers
arr := make([]int, 50)
for i := range arr {
arr[i] = rand.Intn(100) // Random numbers between 0 and 99
}
fmt.Println("Unsorted array:", arr)
// Sort the array
selectionSort(arr)
fmt.Println("Sorted array:", arr)
}