Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(61)

Delta Between Two Patch Sets: doc/progs/sortmain.go

Issue 850041: code review 850041: single argument panic (Closed)
Left Patch Set: Created 15 years ago
Right Patch Set: code review 850041: single argument panic Created 15 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « doc/progs/run ('k') | src/cmd/cgo/ast.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "sort" 9 "sort"
10 ) 10 )
(...skipping 10 matching lines...) Expand all
21 func strings() { 21 func strings() {
22 data := []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"} 22 data := []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}
23 a := sort.StringArray(data) 23 a := sort.StringArray(data)
24 sort.Sort(a) 24 sort.Sort(a)
25 if !sort.IsSorted(a) { 25 if !sort.IsSorted(a) {
26 panic("fail") 26 panic("fail")
27 } 27 }
28 } 28 }
29 29
30 type day struct { 30 type day struct {
31 » num int 31 » num int
32 » shortName string 32 » shortName string
33 » longName string 33 » longName string
34 } 34 }
35 35
36 type dayArray struct { 36 type dayArray struct {
37 data []*day 37 data []*day
38 } 38 }
39 39
40 func (p *dayArray) Len() int { return len(p.data) } 40 func (p *dayArray) Len() int { return len(p.data) }
41 func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num } 41 func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num }
42 func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.dat a[i] } 42 func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.da ta[i] }
43 43
44 func days() { 44 func days() {
45 » Sunday := day{0, "SUN", "Sunday"} 45 » Sunday := day{0, "SUN", "Sunday"}
46 » Monday := day{1, "MON", "Monday"} 46 » Monday := day{1, "MON", "Monday"}
47 » Tuesday := day{2, "TUE", "Tuesday"} 47 » Tuesday := day{2, "TUE", "Tuesday"}
48 Wednesday := day{3, "WED", "Wednesday"} 48 Wednesday := day{3, "WED", "Wednesday"}
49 » Thursday := day{4, "THU", "Thursday"} 49 » Thursday := day{4, "THU", "Thursday"}
50 » Friday := day{5, "FRI", "Friday"} 50 » Friday := day{5, "FRI", "Friday"}
51 » Saturday := day{6, "SAT", "Saturday"} 51 » Saturday := day{6, "SAT", "Saturday"}
52 data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Frida y, &Saturday} 52 data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Frida y, &Saturday}
53 a := dayArray{data} 53 a := dayArray{data}
54 sort.Sort(&a) 54 sort.Sort(&a)
55 if !sort.IsSorted(&a) { 55 if !sort.IsSorted(&a) {
56 panic("fail") 56 panic("fail")
57 } 57 }
58 for _, d := range data { 58 for _, d := range data {
59 fmt.Printf("%s ", d.longName) 59 fmt.Printf("%s ", d.longName)
60 } 60 }
61 fmt.Printf("\n") 61 fmt.Printf("\n")
62 } 62 }
63 63
64 64
65 func main() { 65 func main() {
66 ints() 66 ints()
67 strings() 67 strings()
68 days() 68 days()
69 } 69 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b