package main
import (
"fmt"
"sort"
)
func main() {
Author := []
struct
{
a_name string
a_article
int
a_id
int
}{
{
"Mina"
, 304, 1098},
{
"Cina"
, 634, 102},
{
"Tina"
, 104, 105},
{
"Rina"
, 10, 108},
{
"Sina"
, 234, 103},
{
"Vina"
, 237, 106},
{
"Rohit"
, 56, 107},
{
"Mohit"
, 300, 104},
{
"Riya"
, 4, 101},
{
"Sohit"
, 20, 110},
}
sort.Slice(Author, func(p, q
int
)
bool
{
return
Author[p].a_name < Author[q].a_name })
res1 := sort.SliceIsSorted(Author, func(p, q
int
)
bool
{
return
Author[p].a_name < Author[q].a_name })
if
res1 ==
true
{
fmt.Println(
"Slice is sorted by their names"
)
}
else
{
fmt.Println(
"Slice is not sorted by their names"
)
}
res2 := sort.SliceIsSorted(Author, func(p, q
int
)
bool
{
return
Author[p].a_article < Author[q].a_article })
if
res2 ==
true
{
fmt.Println(
"Slice is sorted by "
+
"their total number of articles"
)
}
else
{
fmt.Println(
"Slice is not sorted by"
+
" their total number of articles"
)
}
sort.Slice(Author, func(p, q
int
)
bool
{
return
Author[p].a_id < Author[q].a_id })
res3 := sort.SliceIsSorted(Author, func(p, q
int
)
bool
{
return
Author[p].a_id < Author[q].a_id })
if
res3 ==
true
{
fmt.Println(
"Slice is sorted by their ids"
)
}
else
{
fmt.Println(
"Slice is not sorted by their ids"
)
}
}