Changes to README

This commit is contained in:
Nocturn9x 2022-03-16 14:18:47 +01:00
parent 667d2502bf
commit 09b73c35e6
1 changed files with 16 additions and 11 deletions

View File

@ -17,7 +17,7 @@ A `LinkedDeque` is a deque based on a doubly linked list.
import nimdeque
queue = newLinkedDeque[int]()
var queue = newLinkedDeque[int]()
# Appends to the tail
queue.add(1)
@ -30,15 +30,15 @@ queue.addLeft(-1)
queue.addLeft(-2)
# 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
echo queue.pop(queue.high())
echo queue.pop(queue.high()) # 2
# This can also be written as
echo queue.pop(^1)
echo queue.pop(^1) # 1
# Pops element at position n
echo queue.pop(n)
# Pops element at position 2
echo queue.pop(2)
# Supports iteration
for i, e in queue:
@ -48,7 +48,11 @@ for i, e in queue:
for e in queue.reversed():
echo e
# Length and last index
echo queue.len()
echo queue.high()
# 'in' operator
echo 5 in queue # false
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
# queue, the higher the time it takes to retrieve it. For
# fast random access, seqs should be used instead
queue[0] # -1
queue[^1]
queue[queue.high()]
echo queue[0] # -1
echo queue[^1] # 2
echo queue[queue.high()] # 2
# It's possible to extend a deque with other deques or with seqs
# of compatible type
@ -72,8 +77,8 @@ queue.extend(other)
# item in the queue, returns -1 if not
# found
queue.find(9999) # -1, not found
queue.find(-1) # 0
echo queue.find(9999) # -1, not found
echo queue.find(-1) # 0
# Clears the queue in O(1) time
queue.clear()