diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-10-15 15:02:59 +0300 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-10-15 15:02:59 +0300 |
commit | 714f574a0029af1fd7de0989eda28df46f5bec4f (patch) | |
tree | 8606fd0eaa357450e3bb248e3550bf9cc617ea61 /queue.py | |
parent | 99fcc543354860ed485b6ded092db4229adcaa16 (diff) | |
download | cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.gz cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.bz2 cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.zip |
feat: cs lesson 4 material
Diffstat (limited to 'queue.py')
-rw-r--r-- | queue.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/queue.py b/queue.py new file mode 100644 index 0000000..4235a7f --- /dev/null +++ b/queue.py @@ -0,0 +1,23 @@ +queue = [None for index in range(0, 10)] +frontPointer = 0 +rearPointer = -1 +queueLength = 0 +queueFull = 10 +def dequeue(): + global queue, queueLength, queueFull, rearPointer + +def enqueue(item): + global queue, queueLength, queueFull, rearPointer + if queueLength < queueFull: + if rearPointer < len(queue) - 1: + rearPointer += 1 + else: + rearPointer = 0 + queueLength += 1 + queue[rearPointer] = item + print(queue) + return + print("ERROR queue length exceeded!") + return +for i in range(13): + enqueue(10 * i) |