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 | 575 Views, 23012 Search Bots | 93 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 575 Views, 23012 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 | 575 Views, 23012 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
- Daily Interview Puzzle: Intersection of Linked Lists
- Kaprekar
- Daily Interview Problem: Merge List Of Number Into Ranges
- ImageMagick Vulnerabilities - CVE-2016–3714
- Consecutive Ones
- Daily Interview Problem: Min Range Needed to Sort
- Plus One
- Detect Linked List Cycle
- Algorithm Interview Question: Max and Min with Limited Comparisons
- Daily Interview Problem: Trapping Rainwater
©2006~2024 SteakOverCooked - 0.00854 Seconds(s) - 2263.886 KB/s - 45 Online Memory: 492.34 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 !