Skip to content

Commit bf6baa0

Browse files
Update queues_using_stacks.py
1 parent df58ecd commit bf6baa0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Queue/queues_using_stacks.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
1212
The program provides the user with a menu to select the operation they want to perform - enqueue, dequeue, or quit. The user can input the value to enqueue, and the program prints the enqueued or dequeued value accordingly.
1313
14+
Summary about the code and time complexity:
15+
16+
This code implements a queue using two stacks.
17+
The enqueue operation is simply implemented by appending an element to one of the stacks, while the dequeue operation involves reversing the order of the elements by popping from one stack and pushing onto the other, and then popping the top element from the second stack.
18+
The time complexity of the enqueue operation is O(1), while the time complexity of the dequeue operation is O(n) in the worst case, where n is the number of elements in the queue. This is because in the worst case, all the elements will need to be moved from one stack to the other during the dequeue operation.
19+
1420
1521
1622
----------------------------------------------------------------------------------------------------------//Python code begins here-----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)