Updated example in README

This commit is contained in:
Nocturn9x 2022-11-09 12:55:53 +01:00
parent 11448193ea
commit eaaac53be0
1 changed files with 12 additions and 6 deletions

View File

@ -29,16 +29,22 @@ queue.addLeft(0)
queue.addLeft(-1)
queue.addLeft(-2)
echo queue
# Pops and returns the first element in O(1) time
echo queue.pop()
echo queue.pop() # -2
echo queue
# Pops and returns the last element in O(1) time
echo queue.pop(queue.high()) # 2
echo queue.pop(queue.high()) # 3
# This can also be written as
echo queue.pop(^1) # 1
echo queue.pop(^1) # 2
echo queue
# Pops element at position 2
echo queue.pop(2) # 0
echo queue.pop(2) # 1
# Supports iteration
for i, e in queue:
@ -61,8 +67,8 @@ echo 0 in queue # true
# queue, the higher the time it takes to retrieve it. For
# fast random access, seqs should be used instead
echo queue[0] # -1
echo queue[^1] # 1
echo queue[queue.high()] # 1
echo queue[^1] # 0
echo queue[queue.high()] # 0
# It's possible to extend a deque with other deques or with seqs