0

Can we use both push and pop in both queue and stack???

7th Aug 2021, 1:05 PM
Minishreddy Vaidhyula
Minishreddy  Vaidhyula  - avatar
5 Réponses
+ 2
Minishreddy Vaidhyula you can , they are just names ,changing the function name won't change the functionality !! But if someone expects you to have name of the methods as push and pop then you can't obviously use any name for it.
7th Aug 2021, 1:18 PM
Abhay
Abhay - avatar
+ 1
Don't we already use it ? In queue we push element from the front while in stack we push element from the back. In queue we remove(pop) element from the front while in stack we remove element from the back. There can be different implementation of both but that's how it works.
7th Aug 2021, 1:08 PM
Abhay
Abhay - avatar
+ 1
you can, but Queue in java api has add() and remove() instead
10th Aug 2021, 8:04 PM
zemiak
0
Can we use add in the place of push in both queue and stack ??
7th Aug 2021, 1:10 PM
Minishreddy Vaidhyula
Minishreddy  Vaidhyula  - avatar