Skip to content

Commit

Permalink
Merge pull request #14 from spbu-coding-2023/avl-hotfix
Browse files Browse the repository at this point in the history
fix: remove getPairs() from AVL tree
  • Loading branch information
VyacheslavIurevich authored Apr 10, 2024
2 parents 51d39b6 + 0ccbaa7 commit cc1c96f
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/main/kotlin/trees/avl/AvlTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ class AvlTree<K : Comparable<K>, V> : AbstractTree<K,V,AvlNode<K,V>>() {

override fun iterator(): Iterator<Pair<K, V>> = AvlTreeIterator(getPairs())

private fun getPairs(): MutableList<Pair<K, V>> {
val trajectory = mutableListOf<Pair<K, V>>()
val stack: MutableList<AvlNode<K, V>?>
var currNode: AvlNode<K, V>? = root ?: return mutableListOf()
stack = mutableListOf(currNode)
while (stack.size > 0) {
currNode = stack[stack.size - 1]
stack.removeAt(stack.size - 1)
if (currNode != null) {
stack.add(currNode.left)
stack.add(currNode.right)
trajectory.add(Pair(currNode.key, currNode.value))
}
}
return trajectory
}
private fun balanceFactor(node: AvlNode<K, V>) = (node.right?.height ?: 0) - (node.left?.height ?: 0)


Expand Down Expand Up @@ -110,4 +94,4 @@ class AvlTree<K : Comparable<K>, V> : AbstractTree<K,V,AvlNode<K,V>>() {



}
}

0 comments on commit cc1c96f

Please sign in to comment.