summaryrefslogtreecommitdiff
path: root/ds/arraylist.go
diff options
context:
space:
mode:
Diffstat (limited to 'ds/arraylist.go')
-rw-r--r--ds/arraylist.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/ds/arraylist.go b/ds/arraylist.go
new file mode 100644
index 0000000..65c42ef
--- /dev/null
+++ b/ds/arraylist.go
@@ -0,0 +1,37 @@
+package ds
+
+import (
+ "fmt"
+ "strings"
+)
+
+type ArrayList []Comparer
+
+func (a ArrayList) FirstN(n int) string {
+ var sb strings.Builder
+ j := n
+
+ length := len(a)
+ if j > length {
+ j = length
+ }
+
+ for i := 0; i < j; i++ {
+ fmt.Fprintf(&sb, "%v ", a[i])
+ }
+
+ if j < length {
+ fmt.Fprintf(&sb, "... ")
+ }
+
+ return sb.String()
+}
+
+func (a ArrayList) Sorted() bool {
+ for i := len(a) - 1; i > 0; i-- {
+ if a[i].Lower(a[i-1]) {
+ return false
+ }
+ }
+ return true
+}