本文整理汇总了Python中datastructures.array.Array.top方法的典型用法代码示例。如果您正苦于以下问题:Python Array.top方法的具体用法?Python Array.top怎么用?Python Array.top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastructures.array.Array
的用法示例。
在下文中一共展示了Array.top方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activity_scheduler
# 需要导入模块: from datastructures.array import Array [as 别名]
# 或者: from datastructures.array.Array import top [as 别名]
def activity_scheduler(s, f):
n = s.length
A = Array.indexed(1, n)
F = Array(list(rbetween(n, 1)))
F.top = n
B = RedBlackTree()
# events contains triples (a, b, c) where a = 0 if the event is finish of an activity and 1 if it is start,
# b as the activity number, and c as the start time or the finish time
events = [(0, i + 1, finish_time) for i, finish_time in enumerate(f)] + \
[(1, i + 1, start_time) for i, start_time in enumerate(s)]
events.sort(key=lambda e: (e[2], e[0]))
for e in events:
if e[0] == 1:
hall_number = pop(F)
A[e[1]] = hall_number
rb_insert(B, Node(e[1], data=hall_number), sentinel=B.nil)
else:
hall = rb_search(B.root, e[1], sentinel=B.nil)
push(F, hall.data)
rb_delete(B, hall, sentinel=B.nil)
return A