-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImplementStackusingQueues.py
More file actions
64 lines (51 loc) · 1.05 KB
/
ImplementStackusingQueues.py
File metadata and controls
64 lines (51 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# encoding: utf-8
"""
@version: 1.0
@author: Ding4it
@license: Apache Licence
@contact: ding4it@gmail.com
@file: ImplementStackusingQueues.py
@time: 2016/1/8 10:53
"""
class Stack(object):
def __init__(self):
"""
initialize your data structure here.
"""
self.__queue__ = []
def push(self, x):
"""
:type x: int
:rtype: nothing
"""
tmp = []
tmp.append(x)
while self.__queue__:
tmp.append(self.__queue__[0])
del self.__queue__[0]
self.__queue__ = tmp
print(self.__queue__)
def pop(self):
"""
:rtype: nothing
"""
if self.empty():
return
del self.__queue__[0]
def top(self):
"""
:rtype: int
"""
return self.__queue__[0]
def empty(self):
"""
:rtype: bool
"""
if not self.__queue__:
return True
else:
return False
A = Stack()
A.push(1)
A.empty()