Categories
LeetCode

LeetCode 232. Implement Queue using Stacks (Java)

Source: https://leetcode.com/problems/implement-queue-using-stacks/

Implement the following operations of a queue using stacks.

  • push(x) — Push element x to the back of queue.
  • pop() — Removes the element from in front of queue.
  • peek() — Get the front element.
  • empty() — Return whether the queue is empty.
Categories
LeetCode

Stack and Queue Data Structure (Java code and Leetcode problems)

Stack and queue are dynamic data structures, both support delete operation.