diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 13:01:36 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 13:01:36 +0100 |
| commit | 390333bb314f6cb25adc5716ea383112860ed342 (patch) | |
| tree | 2b87d5741d84b2cd2d7c74eaaa0f522c3a8a221c /ds/integer.go | |
| parent | deaa4e1c33cd2c1c75f698881918688055abfa51 (diff) | |
add parallelquick and so on
Diffstat (limited to 'ds/integer.go')
| -rw-r--r-- | ds/integer.go | 42 |
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() + } } |
