mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
Merge pull request #1341 from def-/algorithm-reversed
Add reversed proc
This commit is contained in:
@@ -34,6 +34,20 @@ proc reverse*[T](a: var openArray[T]) =
|
||||
## reverses the array `a`.
|
||||
reverse(a, 0, a.high)
|
||||
|
||||
proc reversed*[T](a: openArray[T], first, last: int): seq[T] =
|
||||
## returns the reverse of the array `a[first..last]`.
|
||||
result = newSeq[T](last - first + 1)
|
||||
var x = first
|
||||
var y = last
|
||||
while x <= last:
|
||||
result[x] = a[y]
|
||||
dec(y)
|
||||
inc(x)
|
||||
|
||||
proc reversed*[T](a: openArray[T]): seq[T] =
|
||||
## returns the reverse of the array `a`.
|
||||
reversed(a, 0, a.high)
|
||||
|
||||
proc binarySearch*[T](a: openArray[T], key: T): int =
|
||||
## binary search for `key` in `a`. Returns -1 if not found.
|
||||
var b = len(a)
|
||||
|
||||
@@ -24,6 +24,7 @@ News
|
||||
- Added module ``cpuinfo``.
|
||||
- Added module ``threadpool``.
|
||||
- ``sequtils.distnct`` has been renamed to ``sequtils.deduplicate``.
|
||||
- Added ``algorithm.reversed``
|
||||
|
||||
|
||||
2014-04-21 Version 0.9.4 released
|
||||
|
||||
Reference in New Issue
Block a user