Skip to content

Commit ce7554b

Browse files
author
Hamid Gasmi
committed
Stack and Queue sections are updated
1 parent 6f4c03f commit ce7554b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -554,25 +554,25 @@
554554
- LIFO: Last-In First-Out
555555
- It could be implemented with an array:
556556
- We should keep track of the latestest element pushed index which is different from its capacity `len(array)`
557-
Push(key):
557+
- Push(key):
558558
if max-index + 1 < len(array):
559559
max-index += 1
560560
array[max-index] = key
561-
Top():
561+
- Top():
562562
if max-index >= 0:
563563
return array[max-index]
564-
Pop():
564+
- Pop():
565565
if max-index >= 0:
566566
value = array[max-index]
567567
max-index -= 1
568568
return value
569-
Empty():
569+
- Empty():
570570
return max-index == -1
571571
- It could be implemented with a Singly-Linked-List:
572-
Push(key): list.PushFront(Key)
573-
Top(): return list.TopFront()
574-
Pop(): return list.PopFront()
575-
Empty(): return list.Empty()
572+
- Push(key): list.PushFront(Key)
573+
- Top(): return list.TopFront()
574+
- Pop(): return list.PopFront()
575+
- Empty(): return list.Empty()
576576
- Time Complexity: Array Imp. Singly-Linked List Comment
577577
Push(key): Θ(1) Θ(1)
578578
Key Top(): Θ(1) Θ(1)
@@ -601,23 +601,23 @@
601601
- We should keep track of the latestest inserted element index (we'll use it for reads): `read-index`
602602
- We should keep track of the most recent inserted element index(we'll use it for writes): `write-index`
603603
- Initially: `read-index == write-index == 0`
604-
Empty(): return (read-index == write-index)
605-
Full(): return (read-index == write-index + 1)
606-
Enqueue(key):
604+
- Empty(): return (read-index == write-index)
605+
- Full(): return (read-index == write-index + 1)
606+
- Enqueue(key):
607607
if Not Full():
608608
array[write-index] = key
609609
write-index = write-index + 1 if write-index < len(array) - 1 else 0
610-
Dequeue():
610+
- Dequeue():
611611
if Not Empty():
612612
value = array[read-index]
613613
read-index = read-index + 1 if read-index < len(array) - 1 else 0
614614
return value
615615
- It could be implemented with a Doubly-Linked-List with a tail:
616616
- The list head will be used for reads
617617
- The list writes will be used for writes
618-
Empty(): return list.Empty()
619-
Enqueue(key): list.PushBack(Key)
620-
Dequeue(): list.PopFront()
618+
- Empty(): return list.Empty()
619+
- Enqueue(key): list.PushBack(Key)
620+
- Dequeue(): list.PopFront()
621621
- Time Complexity: Array Imp. Singly-Linked List Comment
622622
Push(key): Θ(1) Θ(1)
623623
Key Top(): Θ(1) Θ(1)

0 commit comments

Comments
 (0)