-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make better checks and fix ordering Structs
- Loading branch information
Showing
4 changed files
with
203 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ordering | ||
|
||
import "sort" | ||
|
||
var _ sort.Interface = (*StingList)(nil) | ||
|
||
// StingList is a list of strings that *can* be sorted. | ||
// | ||
// Implement sort.Interface | ||
type StingList []string | ||
|
||
// Len returns the length of the list. | ||
func (s *StingList) Len() int { | ||
return len(*s) | ||
} | ||
|
||
// Swap swaps the elements with indexes i and j. | ||
func (s StingList) Swap(i, j int) { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
|
||
// Less reports whether the element with index i should sort before the element with index j. | ||
func (s StingList) Less(i, j int) bool { | ||
return s[i] < s[j] | ||
} | ||
|
||
// Sort sorts the list. | ||
func (s *StingList) Sort() { | ||
sort.Sort(s) | ||
} | ||
|
||
// Add adds a string to the list. | ||
func (s *StingList) Add(str string) { | ||
*s = append(*s, str) | ||
} |