Use it like:
const LinkedList = preload("LinkedList.gd")
func _ready():
var ll = LinkedList.new()
ll.push_back(-1)
ll.push_back(5)
ll.push_front(1)
ll.push_front(2)
print(ll.size()) # 4
print(ll.pop_best(funcref(self, "comp"))) # 5
print(ll.pop_back()) # -1
print(ll.pop_front()) # 2
print(ll.size()) # 1
func comp(a,b):
return a > b
@kostasde, thanks for the feedback.
The property naming is not great in the code, which I think is leading to confusion (like here). I would prefer seeing "head" and "tail" used consistently throughout for clarity and will rewrite it when I get a chance. In those terms, "other.next = next" would be "other.head = head" which is incorrect because we are chaining this item to the other item, i.e. this "head" to other's "tail".