summaryrefslogtreecommitdiff
path: root/ds/integer.go
diff options
context:
space:
mode:
Diffstat (limited to 'ds/integer.go')
-rw-r--r--ds/integer.go42
1 files changed, 23 insertions, 19 deletions
diff --git a/ds/integer.go b/ds/integer.go
index 296e5bb..e8936c8 100644
--- a/ds/integer.go
+++ b/ds/integer.go
@@ -12,12 +12,16 @@ type Integer struct {
func RandomIntegers(length, max int) ArrayList {
a := make(ArrayList, length)
for i := 0; i < length; i++ {
- a[i] = Integer{rand.Intn(max)}
+ if max > 0 {
+ a[i] = Integer{rand.Intn(max)}
+ continue
+ }
+ a[i] = Integer{rand.Int()}
}
return a
}
-func SortedIntegers(length int) ArrayList {
+func AscendingIntegers(length int) ArrayList {
a := make(ArrayList, length)
for i := 0; i < length; i++ {
a[i] = Integer{i}
@@ -25,7 +29,7 @@ func SortedIntegers(length int) ArrayList {
return a
}
-func ReverseSortedIntegers(length int) ArrayList {
+func DescendingIntegers(length int) ArrayList {
a := make(ArrayList, length)
j := length
for i := 0; i < length; i++ {
@@ -64,24 +68,24 @@ func (i Integer) HigherEqual(j Elem) bool {
}
func (i Integer) Compare(j Elem) int {
- jVal := j.Int()
- switch {
- case i.Val < jVal:
- return -1
- case i.Val > jVal:
- return 1
- }
+ jVal := j.Int()
+ switch {
+ case i.Val < jVal:
+ return -1
+ case i.Val > jVal:
+ return 1
+ }
return 0
}
func (i Integer) CompareCB(j Elem, lowerCB, higherCB, equalsCB func()) {
- jVal := j.Int()
- switch {
- case i.Val < jVal:
- lowerCB()
- case i.Val > jVal:
- higherCB()
- default:
- equalsCB()
- }
+ jVal := j.Int()
+ switch {
+ case i.Val < jVal:
+ lowerCB()
+ case i.Val > jVal:
+ higherCB()
+ default:
+ equalsCB()
+ }
}