Changes to README
This commit is contained in:
parent
667d2502bf
commit
09b73c35e6
27
README.md
27
README.md
|
@ -17,7 +17,7 @@ A `LinkedDeque` is a deque based on a doubly linked list.
|
||||||
import nimdeque
|
import nimdeque
|
||||||
|
|
||||||
|
|
||||||
queue = newLinkedDeque[int]()
|
var queue = newLinkedDeque[int]()
|
||||||
|
|
||||||
# Appends to the tail
|
# Appends to the tail
|
||||||
queue.add(1)
|
queue.add(1)
|
||||||
|
@ -30,15 +30,15 @@ queue.addLeft(-1)
|
||||||
queue.addLeft(-2)
|
queue.addLeft(-2)
|
||||||
|
|
||||||
# Pops and returns the first element in O(1) time
|
# Pops and returns the first element in O(1) time
|
||||||
queue.pop()
|
echo queue.pop()
|
||||||
|
|
||||||
# Pops and returns the last element in O(1) time
|
# Pops and returns the last element in O(1) time
|
||||||
echo queue.pop(queue.high())
|
echo queue.pop(queue.high()) # 2
|
||||||
# This can also be written as
|
# This can also be written as
|
||||||
echo queue.pop(^1)
|
echo queue.pop(^1) # 1
|
||||||
|
|
||||||
# Pops element at position n
|
# Pops element at position 2
|
||||||
echo queue.pop(n)
|
echo queue.pop(2)
|
||||||
|
|
||||||
# Supports iteration
|
# Supports iteration
|
||||||
for i, e in queue:
|
for i, e in queue:
|
||||||
|
@ -48,7 +48,11 @@ for i, e in queue:
|
||||||
for e in queue.reversed():
|
for e in queue.reversed():
|
||||||
echo e
|
echo e
|
||||||
|
|
||||||
|
# Length and last index
|
||||||
echo queue.len()
|
echo queue.len()
|
||||||
|
echo queue.high()
|
||||||
|
|
||||||
|
# 'in' operator
|
||||||
echo 5 in queue # false
|
echo 5 in queue # false
|
||||||
echo 0 in queue # true
|
echo 0 in queue # true
|
||||||
|
|
||||||
|
@ -56,9 +60,10 @@ echo 0 in queue # true
|
||||||
# Note that the further the item is from either end of the
|
# Note that the further the item is from either end of the
|
||||||
# queue, the higher the time it takes to retrieve it. For
|
# queue, the higher the time it takes to retrieve it. For
|
||||||
# fast random access, seqs should be used instead
|
# fast random access, seqs should be used instead
|
||||||
queue[0] # -1
|
echo queue[0] # -1
|
||||||
queue[^1]
|
echo queue[^1] # 2
|
||||||
queue[queue.high()]
|
echo queue[queue.high()] # 2
|
||||||
|
|
||||||
|
|
||||||
# It's possible to extend a deque with other deques or with seqs
|
# It's possible to extend a deque with other deques or with seqs
|
||||||
# of compatible type
|
# of compatible type
|
||||||
|
@ -72,8 +77,8 @@ queue.extend(other)
|
||||||
# item in the queue, returns -1 if not
|
# item in the queue, returns -1 if not
|
||||||
# found
|
# found
|
||||||
|
|
||||||
queue.find(9999) # -1, not found
|
echo queue.find(9999) # -1, not found
|
||||||
queue.find(-1) # 0
|
echo queue.find(-1) # 0
|
||||||
|
|
||||||
# Clears the queue in O(1) time
|
# Clears the queue in O(1) time
|
||||||
queue.clear()
|
queue.clear()
|
||||||
|
|
Loading…
Reference in New Issue