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 (
|
|
|
|
"fmt";
|
|
|
|
"sort";
|
|
|
|
)
|
2008-09-15 12:48:37 -06:00
|
|
|
|
|
|
|
func ints() {
|
2009-03-03 09:39:12 -07:00
|
|
|
data := []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586};
|
2009-01-09 16:16:31 -07:00
|
|
|
a := sort.IntArray(data);
|
|
|
|
sort.Sort(a);
|
|
|
|
if !sort.IsSorted(a) {
|
2008-09-15 12:48:37 -06:00
|
|
|
panic()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strings() {
|
2009-03-03 09:39:12 -07:00
|
|
|
data := []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};
|
2009-01-09 16:16:31 -07:00
|
|
|
a := sort.StringArray(data);
|
|
|
|
sort.Sort(a);
|
|
|
|
if !sort.IsSorted(a) {
|
2008-09-15 12:48:37 -06:00
|
|
|
panic()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 18:54:07 -07:00
|
|
|
type day struct {
|
2008-09-15 12:48:37 -06:00
|
|
|
num int;
|
|
|
|
short_name string;
|
|
|
|
long_name string;
|
|
|
|
}
|
|
|
|
|
2009-01-15 18:54:07 -07:00
|
|
|
type dayArray struct {
|
|
|
|
data []*day;
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
|
2009-01-15 18:54:07 -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() {
|
2009-03-03 09:39:12 -07: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" };
|
|
|
|
data := []*day{&Tuesday, &Thursday, &Sunday, &Monday, &Friday};
|
|
|
|
a := dayArray{data};
|
2009-01-09 16:16:31 -07:00
|
|
|
sort.Sort(&a);
|
|
|
|
if !sort.IsSorted(&a) {
|
2008-09-15 12:48:37 -06:00
|
|
|
panic()
|
|
|
|
}
|
2009-01-09 16:16:31 -07:00
|
|
|
for i, d := range data {
|
2009-03-18 15:09:16 -06:00
|
|
|
fmt.Printf("%s ", d.long_name)
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
2009-03-18 15:09:16 -06:00
|
|
|
fmt.Printf("\n")
|
2008-09-15 12:48:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ints();
|
|
|
|
strings();
|
|
|
|
days();
|
|
|
|
}
|