GitXplorerGitXplorer
k

Swift-AVL-Tree

public
5 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
c83256dbe2ae8d35d1a54dd02baf1d6dd9a4400b

Update README.md

kkingreza committed 8 years ago
Unverified
7dd3932f7e7dd9208f089234791d6dd79cea1a4b

Update README.md

kkingreza committed 8 years ago
Unverified
76bff6912c16b41d8e8d08edab51306f6e514fde

Update README.md

kkingreza committed 8 years ago
Unverified
f9d79414a4eef1e2273a1dcd9e40f41426d019ac

Optional clean up

kkingreza committed 9 years ago
Unverified
fc5714fe79b5689670d1efefa8d5172d44db6aa5

Main clean up

kkingreza committed 9 years ago
Unverified
e252261a3533d522abae379188c8d59693e9762a

documentation and clean up

kkingreza committed 9 years ago

README

The README file for this repository.

Swift-AVL-Tree

A generic self balancing AVL tree with SequenceType, CollectionType and ArrayLiteralConvertible extensions.

Usage Example:

/* 
  Create tree with associated type (must implement Comparable) */
var tree = BinarySearchTree<Int>()

/* Insert items, tree will balance for optimal retrieval */
tree.insert(7)
tree.insert(3)
tree.insert(4)
tree.insert(9)
tree.insert(2)
tree.insert(1)

//Use find to find a node in the tree
var node = tree.findNode(7)

/*
 All items in the tree are accessible through a subscript. 
 You get a sorted array from lowest to highest because 
 of AVL self balancing behaviour [Benefit of CollectionType Protocol] */

for index in 0..<tree.count {
  print(tree[index])
}

/*
  You have access to all CollectionType methods like 
  reverse [Benefit of CollectionType Protocol] */
  
var reverse = tree.reverse()

/* 
  You can traverse the tree using for-in loop [Benefit of SequenceType Protocol] */
  
for value in reverse {
  print(value)
}

/*
 You can build a tree by simply assigning an array to it 
 instead of inserting elements one by one 
 [Benefit of ArrayLiteralConvertible Protcol] */

var newTree: BinarySearchTree = ["hello", "world", "this", "is", "a", "new", "day"]

_ = newTree.map {print($0)}