Skip to content

Commit 77c4ce0

Browse files
Update stacks_with_queues.cpp
1 parent 21b8907 commit 77c4ce0

File tree

1 file changed

+0
-16
lines changed

1 file changed

+0
-16
lines changed

Diff for: Stacks/stacks_with_queues.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,3 @@ class MyStack {
6464
}
6565
};
6666

67-
68-
/*
69-
This implementation maintains two queues, queue1 and queue2, where queue1 always holds the elements in the stack. When pushing a new element, it is added to queue2, and then all the elements from queue1 are moved to queue2, making the newly added element the front/top of the stack. Finally, the names of the two queues are swapped to maintain the order.
70-
71-
The pop() function removes and returns the front/top element of queue1, while the top() function returns the front/top element without removing it. Both functions check if queue1 is empty and throw an exception if the stack is empty.
72-
73-
The empty() function checks if queue1 is empty and returns true if it is, indicating an empty stack.
74-
75-
Time complexity
76-
77-
push(x): O(n)
78-
pop(): O(1)
79-
top(): O(1)
80-
empty(): O(1)
81-
*/
82-

0 commit comments

Comments
 (0)