2008-09-15 12:48:37 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-03-18 15:09:16 -06:00
|
|
|
import (
|
2009-12-15 16:29:53 -07:00
|
|
|
"fmt"
|
2010-12-09 14:18:31 -07:00
|
|
|
"./sort"
|
2009-03-18 15:09:16 -06:00
|
|
|
)
|
2008-09-15 12:48:37 -06:00
|
|
|
|
|
|
|
func ints() {
|
2009-12-15 16:29:53 -07:00
|
|
|
data := []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586}
|
2011-06-10 17:25:18 -06:00
|
|
|
a := sort.IntSlice(data)
|
2009-12-15 16:29:53 -07:00
|
|
|
sort.Sort(a)
|
2009-01-09 16:16:31 -07:00
|
|
|
if !sort.IsSorted(a) {
|
2010-03-30 11:34:57 -06:00
|
|
|
panic("fail")
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strings() {
|
2009-12-15 16:29:53 -07:00
|
|
|
data := []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}
|
2011-06-10 17:25:18 -06:00
|
|
|
a := sort.StringSlice(data)
|
2009-12-15 16:29:53 -07:00
|
|
|
sort.Sort(a)
|
2009-01-09 16:16:31 -07:00
|
|
|
if !sort.IsSorted(a) {
|
2010-03-30 11:34:57 -06:00
|
|
|
panic("fail")
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 18:54:07 -07:00
|
|
|
type day struct {
|
2009-12-15 16:29:53 -07:00
|
|
|
num int
|
|
|
|
shortName string
|
|
|
|
longName string
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
|
2009-01-15 18:54:07 -07:00
|
|
|
type dayArray struct {
|
2009-12-15 16:29:53 -07:00
|
|
|
data []*day
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
|
2009-12-15 16:29:53 -07:00
|
|
|
func (p *dayArray) Len() int { return len(p.data) }
|
|
|
|
func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num }
|
|
|
|
func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i] }
|
2008-09-15 12:48:37 -06:00
|
|
|
|
|
|
|
func days() {
|
2010-03-30 11:34:57 -06:00
|
|
|
Sunday := day{0, "SUN", "Sunday"}
|
|
|
|
Monday := day{1, "MON", "Monday"}
|
|
|
|
Tuesday := day{2, "TUE", "Tuesday"}
|
|
|
|
Wednesday := day{3, "WED", "Wednesday"}
|
|
|
|
Thursday := day{4, "THU", "Thursday"}
|
|
|
|
Friday := day{5, "FRI", "Friday"}
|
|
|
|
Saturday := day{6, "SAT", "Saturday"}
|
2009-12-15 16:29:53 -07:00
|
|
|
data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Friday, &Saturday}
|
|
|
|
a := dayArray{data}
|
|
|
|
sort.Sort(&a)
|
2009-01-09 16:16:31 -07:00
|
|
|
if !sort.IsSorted(&a) {
|
2010-03-30 11:34:57 -06:00
|
|
|
panic("fail")
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
2009-09-15 13:42:24 -06:00
|
|
|
for _, d := range data {
|
2009-11-01 21:47:03 -07:00
|
|
|
fmt.Printf("%s ", d.longName)
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
2009-10-13 13:37:04 -06:00
|
|
|
fmt.Printf("\n")
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
2009-12-15 16:29:53 -07:00
|
|
|
ints()
|
|
|
|
strings()
|
|
|
|
days()
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|