File: root - text - article - 2019 - 11 - queue-using-two-stacks.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 592 Views, 24594 Search Bots | 93 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 592 Views, 24594 Search Bots | 93 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Apple:
Implement a queue class using two stacks. A queue is a data structure that supports the FIFO protocol (First in = first out). Your class should support the enqueue and dequeue methods like a standard queue.
Here's a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 592 Views, 24594 Search Bots | 93 Words Implement a queue class using two stacks. A queue is a data structure that supports the FIFO protocol (First in = first out). Your class should support the enqueue and dequeue methods like a standard queue.
Here's a starting point:
class Queue:
def __init__(self):
# Fill this in.
def enqueue(self, val):
# Fill this in.
def dequeue(self):
# Fill this in.
q = Queue()
q.enqueue(1)
q.enqueue(2)
q.enqueue(3)
print q.dequeue()
print q.dequeue()
print q.dequeue()
# 1 2 3
Related Articles
- Algorithm Interview Question: Symmetric k-ary Tree
- Top K Frequent words
- [Daily Problem] Longest Increasing Subsequence
- Sort a Partially Sorted List
- Daily Interview Problem: 3 Sum
- Spreadsheet Columns
- Daily Interview Problem: Largest Product of 3 Elements I
- Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
- Daily Interview Problem: Contiguous Subarray with Maximum Sum
- Daily Interview Problem: Merge K Sorted Linked Lists
©2006~2024 SteakOverCooked - 0.00635 Seconds(s) - 3123.554 KB/s - 14 Online Memory: 494.84 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !