golang sort

package main

import (
    "fmt"
    "sort"
)

type Person struct {
    Name string
    Age  int
}

func main() {
    // Step 1: Create a slice of Person structs
    people := []Person{
        {"Alice", 30},
        {"Bob", 25},
        {"Charlie", 35},
    }

    // Step 2: Define a custom sorting criteria using a custom Less function
    lessFunc := func(i, j int) bool {
        return people[i].Age < people[j].Age
    }

    // Step 3: Sort the slice using the custom Less function
    sort.Slice(people, lessFunc)

    // Step 4: Print the sorted slice
    fmt.Println("Sorted by Age:", people)
}