Example #1
0
func TreeSort(data []int) {
	if len(data) <= 1 {
		return
	}
	root := NewTree(nil, data[0]) //root node
	for i := 1; i < len(data); i++ {
		root.NewNode(data[i]) //filling up the tree
	}
	var sorted vector.IntVector
	var sortIntoArray func(*Tree) //declared to use recursively
	sortIntoArray = func(node *Tree) {
		if node == nil {
			return
		}
		sortIntoArray(node.left)
		sorted.Push(node.val)
		sortIntoArray(node.right)
	}
	sortIntoArray(root)
	copy(data, sorted.Data()) //copy the sorted to the source
}
Example #2
0
func lexeme(runes vector.IntVector) string {
	return string(runes.Data())
}