У нас вы можете посмотреть бесплатно Implement Queue using Stack (with Example) или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
This lecture explains two methods to implement queue using stacks only. The first method assumes Enqueue operation to be costly and second method assumes dequeue operation to be costly. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :) Algo: EnQueue Costly enQueue(q, x) 1) While stack1 is not empty, push everything from stack1 to stack2. 2) Push x to stack1 (assuming size of stacks is unlimited). 3) Push everything back to stack1. Here time complexity will be O(n) deQueue(q) 1) If stack1 is empty then error 2) Pop an item from stack1 and return it Here time complexity will be O(1) CODE LINK: https://drive.google.com/open?id=1B4O... Algo: DeQueue Costly enQueue(q, x) 1) Push x to stack1 (assuming size of stacks is unlimited). Here time complexity will be O(1) deQueue(q) 1) If both stacks are empty then error. 2) If stack2 is empty While stack1 is not empty, push everything from stack1 to stack2. 3) Pop the element from stack2 and return it. Here time complexity will be O(n) CODE LINK: https://drive.google.com/open?id=1fqt...