This commit is contained in:
Mari Wahl 2015-01-10 01:09:23 -05:00
parent bc442a0727
commit c3cb3f1c1b
2 changed files with 34 additions and 25 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
# Time: 5 min
__author__ = "bt3"
@ -8,33 +9,39 @@ class Queue(object):
self.enq = []
self.deq = []
def enqueue(self, value):
self.enq.append(value)
def enqueue(self, item):
return self.enq.append(item)
def dequeue(self):
def deque(self):
if not self.deq:
while self.enq:
self.deq.append(self.enq.pop())
return self.deq.pop()
def isEmpty(self):
return not (self.enq + self.deq)
def peak(self):
if not self.deq:
while self.enq:
self.deq.append(self.enq.pop())
if self.deq:
return self.deq[-1]
def size(self):
return len(self.enq) + len(self.deq)
def isempty(self):
return not (self.enq + self.deq)
if __name__ == '__main__':
q = Queue()
for i in range(1,10):
for i in range(1,11):
q.enqueue(i)
assert(q.isEmpty() == False)
assert(q.size() == 9)
for i in range(1, 10):
print q.dequeue()
assert(q.isEmpty() == True)
print 'Size:', q.size()
print 'Is empty?', q.isempty()
print 'Peak: ', q.peak()
print
print 'Dequeuing...'
for i in range(10):
print q.deque()
print 'Size:', q.size()
print 'Is empty?', q.isempty()
print 'Peak: ', q.peak()

View File

@ -11,20 +11,22 @@ def find_long_con_inc(seq):
[-2, 3, 5]
>>> find_long_con_inc([1, 3, -2, 3, 5, 6])
[-2, 3, 5, 6]
>>> find_long_con_inc([1, 3, 4, -13, 2, 5, 8, -1, 2,-17])
[-13, 2, 5, 8]
'''
aux = []
result = []
res, aux = [], []
seq.append(-float('infinity'))
for i, pivot in enumerate(seq[:-1]):
aux.append(pivot)
if pivot > seq[i+1]:
if len(aux) > len(result):
result = aux
for i, n in enumerate(seq[:-1]):
aux.append(n)
if n > seq[i+1]:
if len(res) < len(aux):
res = aux[:]
aux = []
return result
return res
if __name__ == '__main__':