package school
import (
"sort"
)
type School map[int][]string
type Grade struct {
grade int
name []string
}
type Grades []Grade
func (g Grades) Len() int {
return len(g)
}
func (g Grades) Less(i, j int) bool {
return g[i].grade < g[j].grade
}
func (g Grades) Swap(i, j int) {
g[i], g[j] = g[j], g[i]
return
}
func New() *School {
return &School{}
}
func (s *School) Add(student string, grade int) {
(*s)[grade] = append((*s)[grade], student)
}
func (s *School) Grade(level int) []string {
return (*s)[level]
}
func (s *School) Enrollment() []Grade {
var ret Grades
for k, v := range *s {
sort.Strings(v)
ret = append(ret, Grade{k, v})
}
sort.Sort(ret)
return ret
}