Heap (gb.data)
该类实现动态堆数据结构。它可以是最小堆或最大堆,具体取决于在构造时指定的模式。
“动态”意味着这个类允许更新堆中已经存在的元素的数据或位置。
Properties
Count
|
Return the number of elements in the Heap.
|
First
|
Return or set the first element of the Heap.
|
IsEmpty
|
Return whether the Heap is empty.
|
Methods
Insert
|
Insert an element into the Heap.
|
Remove
|
Remove the first element.
|
Update
|
Find all occurences of Old' and replace them by New'. This is an O(n)
operation. Additionally the heap has to be rebuilt as soon as there is
more than one replacement made.
|
堆中的对象都是变量。堆中的顺序是通过比较这些变量值来隐式定义的。
可以在其中放入基本数据类型值(布尔值、整数、字符串等)和对象。
特殊的 _compare() 方法用于比较对象。
请注意,不能将对象与基本数据类型或Gambas中不同类的对象进行比较(在撰写本文时)。
如果不能在刚刚定义的意义上保持堆的同质性,那么堆将在尝试排序时引发错误。
参见
维基百科上的堆