问题队列相关代码和实例,请勿粘贴截图
python
运行结果及报错内容
用python完成,还要可以正常运行
队列:
代码如下:
class Queue:
def __init__(self):
self.s = []
def pop(self):
val = self.s[0]
del self.s[0]
return val
def push(self,val):
self.s.append(val)
def isEmpty(self):
if len(self.s) == 0:
return True
else:
return False
# 从西向东房屋的高度
h = [33,44,22,35,18,24,23,33,23,18]
ss = Queue()
n = len(h)
for i in h[::-1]:
ss.push(i)
hmax = h[n-1]
i = n
print('海景房:')
print('id=%d:height=%d'%(i,hmax))
ss.pop()
i-=1
while ss.isEmpty()==False:
t = ss.pop()
if t > hmax:
print('id=%d:height=%d'%(i,t))
hmax = t
i-=1
else:
i-=1