| // 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. |
| seq := Sequence{6, 2, -1, 44, 16} |
| // Methods required by sort.Interface. |
| func (s Sequence) Len() int { |
| func (s Sequence) Less(i, j int) bool { |
| func (s Sequence) Swap(i, j int) { |
| // Copy returns a copy of the Sequence. |
| func (s Sequence) Copy() Sequence { |
| copy := make(Sequence, 0, len(s)) |
| return append(copy, s...) |
| // Method for printing - sorts the elements before printing. |
| func (s Sequence) String() string { |
| s = s.Copy() // Make a copy; don't overwrite argument. |
| for i, elem := range s { // Loop is O(N²); will fix that in next example. |