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 | 576 Views, 23081 Search Bots | 93 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 576 Views, 23081 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 | 576 Views, 23081 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: Subarray With Target Sum
- Daily Interview Problem: Largest Product of 3 Elements I
- Daily Interview Problem: Circle of Chained Words
- Most Frequent Subtree Sum
- Reverse a Directed Graph
- Maximum In A Stack
- Spreadsheet Columns
- [Daily Problem] Longest Increasing Subsequence
- Daily Interview Problem: Sort Colors
- Daily Interview Problem: Merge List Of Number Into Ranges
©2006~2024 SteakOverCooked - 0.00766 Seconds(s) - 2744.453 KB/s - 23 Online Memory: 493.82 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 !