I’m experimenting with Binary Trees (Which are very new to me) and am having trouble with one of my functions.

```
--Testing making binary Trees in Lua
Node = {}
Node.__index = Node
--Constructor
function Node:new(data)
local self = setmetatable({}, Node)
self.leaf = data
self.left = nil
self.right = nil
return self
end
--Methods
function Node:getLeafs()
if not self then
return nil
end
if (self.left == nil and self.right == nil) then
return self.leaf
else
return self.getLeafs(self.left), self.getLeafs(self.right)
end
end
local root = Node:new(1)
root.left = Node:new(2)
root.right = Node:new(3)
root.left.left = Node:new(4)
root.left.right = Node:new(5)
root.right.left = Node:new(6)
root.right.right = Node:new(7)
print(root:getLeafs())
```

Apart from the fact that some of this may not be correct, as I am also figuring out OOP, it doesn’t function correctly. The method getLeafs() is supposed to return the lowest leafs on the tree, however it skips one of them.

The tree I created in the example:

```
1
/ \
2 3
/ \ / \
4 5 6 7
```

The correct output would be:

4 5 6 7

However, the current output is:

4 6 7

I tried removing the 4 leaf, and it comes up as:

nil 6 7

If anyone could help me figure this out, or come up with better code, that would be great! Thanks in advance!