WARNING
Old usage sample:
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
</details>
@Ranpu123 I think you are right, the head/tail naming is reversed, but it does not effect the behaviour of the list. The code is actually doing the right thing as is. You can test that the current code is working correctly re head and tail with this:
The output is as expected:
Swapping the commented line, to deliberately add the "middle" item to the front of the list instead also gives the expected result:
For the sake of making the code read correctly, to remove this understandable confusion with the naming, you can simply swap the naming of _head and _tail in the code. Do a CTL+H replace three times as follows:
and now the code will read correctly.