设为首页 加入收藏

TOP

使用 Go 语言实现二叉搜索树(三)
2023-08-06 07:49:42 】 浏览:156
Tags:使用 索树
quot;3", "6", "5", "7", "10", "9", "11"}) } } func TestPostOrderTraverse(t *testing.T) { var result []string bst.PostOrderTraverse(func(i Item) { result = append(result, fmt.Sprintf("%s", i)) }) if !isSameSlice(result, []string{"1", "3", "2", "5", "7", "6", "4", "9", "11", "10", "8"}) { t.Errorf("Traversal order incorrect, got %v instead of %v", result, []string{"1", "3", "2", "5", "7", "6", "4", "9", "11", "10", "8"}) } } func TestMin(t *testing.T) { if fmt.Sprintf("%s", *bst.Min()) != "1" { t.Errorf("min should be 1") } } func TestMax(t *testing.T) { if fmt.Sprintf("%s", *bst.Max()) != "11" { t.Errorf("max should be 11") } } func TestSearch(t *testing.T) { if !bst.Search(1) || !bst.Search(8) || !bst.Search(11) { t.Errorf("search not working") } } func TestRemove(t *testing.T) { bst.Remove(1) if fmt.Sprintf("%s", *bst.Min()) != "2" { t.Errorf("min should be 2") } }

上文中的全部源码都是经过测试的,可以直接运行,并且已经上传到了 GitHub,需要的同学可以自取。

以上就是本文的全部内容,如果觉得还不错的话欢迎点赞转发关注,感谢支持。


源码地址:

推荐阅读:

参考文章:

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[golang]使用tail追踪文件变更 下一篇Go 语言入门指南: 环境搭建、基础..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目