diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 16:00:07 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 16:00:07 +0100 |
| commit | 719321d413bcc61e56786399799a9c80e94ab5d8 (patch) | |
| tree | d97d67fd8b1b42f625c91a9f0c8d6b29819824e0 /ds | |
| parent | b8c45f87d6f7251701f95eb6b8ac1efd4255d298 (diff) | |
fortune not found
Quick commit
Diffstat (limited to 'ds')
| -rw-r--r-- | ds/arraylist.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/ds/arraylist.go b/ds/arraylist.go index 5964b88..8e99384 100644 --- a/ds/arraylist.go +++ b/ds/arraylist.go @@ -8,9 +8,9 @@ import ( type ArrayList []int -func NewRandomArrayList(length, max int) ArrayList { - a := make(ArrayList, length) - for i := 0; i < length; i++ { +func NewRandomArrayList(l, max int) ArrayList { + a := make(ArrayList, l) + for i := 0; i < l; i++ { if max > 0 { a[i] = rand.Intn(max) continue @@ -20,18 +20,18 @@ func NewRandomArrayList(length, max int) ArrayList { return a } -func NewAscendingArrayList(length int) ArrayList { - a := make(ArrayList, length) - for i := 0; i < length; i++ { +func NewAscendingArrayList(l int) ArrayList { + a := make(ArrayList, l) + for i := 0; i < l; i++ { a[i] = i } return a } -func NewDescendingArrayList(length int) ArrayList { - a := make(ArrayList, length) - j := length - 1 - for i := 0; i < length; i++ { +func NewDescendingArrayList(l int) ArrayList { + a := make(ArrayList, l) + j := l - 1 + for i := 0; i < l; i++ { a[i] = j j-- } @@ -42,16 +42,16 @@ func (a ArrayList) FirstN(n int) string { var sb strings.Builder j := n - length := len(a) - if j > length { - j = length + l := len(a) + if j > l { + j = l } for i := 0; i < j; i++ { fmt.Fprintf(&sb, "%v ", a[i]) } - if j < length { + if j < l { fmt.Fprintf(&sb, "... ") } @@ -68,7 +68,7 @@ func (a ArrayList) Sorted() bool { } func (a ArrayList) Swap(i, j int) { - tmp := a[i] + aux := a[i] a[i] = a[j] - a[j] = tmp + a[j] = aux } |
