Skip to content

hslam/avl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

avl

PkgGoDev Build Status codecov Go Report Card LICENSE

Package avl implements an AVL tree.

insertdelete

searchiterate

Get started

Install

go get github.com/hslam/avl

Import

import "github.com/hslam/avl"

Usage

Example

package main

import (
	"fmt"
	"github.com/hslam/avl"
)

func main() {
	tree := avl.New()
	str := String("Hello World")
	tree.Insert(str)
	fmt.Println(tree.Search(str))
	tree.Delete(str)
}

type String string

func (a String) Less(b avl.Item) bool {
	return a < b.(String)
}

Output

Hello World

Iterator Example

package main

import (
	"fmt"
	"github.com/hslam/avl"
)

func main() {
	tree := avl.New()
	l := "MNOLKQPHIA"
	for _, v := range l {
		tree.Insert(String(v))
	}
	iter := tree.Min()
	for iter != nil {
		fmt.Printf("%s\t", iter.Item())
		iter = iter.Next()
	}
}

type String string

func (a String) Less(b avl.Item) bool {
	return a < b.(String)
}

AVL Tree

avl

Output

A	H	I	K	L	M	N	O	P	Q

License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

avl was written by Meng Huang.