广告
返回顶部
首页 > 资讯 > 后端开发 > GO >Go语言数据结构之二叉树可视化详解
  • 370
分享到

Go语言数据结构之二叉树可视化详解

2024-04-02 19:04:59 370人浏览 独家记忆
摘要

目录题目源代码做题思路扩展左右并列展示上下并列展示总结回顾题目 以图形展示任意二叉树,如下图,一个中缀表达式表示的二叉树:3.14*r²*h/3 源代码 package

题目

以图形展示任意二叉树,如下图,一个中缀表达式表示的二叉树:3.14*r²*h/3

源代码

package main
 
import (
    "fmt"
    "io"
    "os"
    "os/exec"
    "strconv"
    "strings"
)
 
type any = interface{}
 
type btnode struct {
    Data   any
    Lchild *btNode
    Rchild *btNode
}
 
type biTree struct {
    Root *btNode
    Info *biTreeInfo
}
 
type biTreeInfo struct {
    Data                []any
    DataLevel           [][]any
    L, R                []bool
    X, Y, W             []int
    Index, Nodes        int
    Width, Height       int
    MarginX, MarginY    int
    SpaceX, SpaceY      int
    SvgWidth, SvgHeight int
    SvgXml              string
}
 
func Build(Data ...any) *biTree {
    if len(Data) == 0 || Data[0] == nil {
        return &biTree{}
    }
    node := &btNode{Data: Data[0]}
    Queue := []*btNode{node}
    for lst := Data[1:]; len(lst) > 0 && len(Queue) > 0; {
        cur, val := Queue[0], lst[0]
        Queue, lst = Queue[1:], lst[1:]
        if val != nil {
            cur.Lchild = &btNode{Data: val}
            Queue = append(Queue, cur.Lchild)
        }
        if len(lst) > 0 {
            val, lst = lst[0], lst[1:]
            if val != nil {
                cur.Rchild = &btNode{Data: val}
                Queue = append(Queue, cur.Rchild)
            }
        }
    }
    return &biTree{Root: node}
}
 
func BuildFromList(List []any) *biTree {
    return Build(List...)
}
 
func AinArray(sub int, array []int) int {
    for idx, arr := range array {
        if sub == arr {
            return idx
        }
    }
    return -1
}
 
func Pow2(x int) int { //x>=0
    res := 1
    for i := 0; i < x; i++ {
        res *= 2
    }
    return res
}
 
func Max(L, R int) int {
    if L > R {
        return L
    } else {
        return R
    }
}
 
func (bt *btNode) MaxDepth() int {
    if bt == nil {
        return 0
    }
    Lmax := bt.Lchild.MaxDepth()
    Rmax := bt.Rchild.MaxDepth()
    return 1 + Max(Lmax, Rmax)
}
 
func (bt *btNode) Coordinate(x, y, w int) []any {
    var res []any
    if bt != nil {
        L, R := bt.Lchild != nil, bt.Rchild != nil
        res = append(res, []any{bt.Data, L, R, x, y, w})
        res = append(res, bt.Lchild.Coordinate(x-w, y+1, w/2)...)
        res = append(res, bt.Rchild.Coordinate(x+w, y+1, w/2)...)
    }
    return res
}
 
func (bt *biTree) NodeInfo() []any {
    return bt.Root.Coordinate(0, 0, Pow2(bt.Root.MaxDepth()-2))
}
 
func (bt *biTree) TreeInfo() {
    height := bt.Root.MaxDepth()
    width := Pow2(height - 1)
    lsInfo := bt.NodeInfo()
    btInfo := &biTreeInfo{
        Height: height,
        Width:  width,
        Nodes:  len(lsInfo),
    }
    for _, data := range lsInfo {
        for i, info := range data.([]any) {
            switch i {
            case 0:
                btInfo.Data = append(btInfo.Data, info.(any))
            case 1:
                btInfo.L = append(btInfo.L, info.(bool))
            case 2:
                btInfo.R = append(btInfo.R, info.(bool))
            case 3:
                btInfo.X = append(btInfo.X, info.(int))
            case 4:
                btInfo.Y = append(btInfo.Y, info.(int))
            case 5:
                btInfo.W = append(btInfo.W, info.(int))
            }
        }
    }
    for j, k := 0, width*2; j < height; j++ {
        DLevel := []any{}
        for i := k / 2; i < width*2; i += k {
            index := AinArray(i-width, btInfo.X)
            if index > -1 {
                DLevel = append(DLevel, btInfo.Data[index])
            } else {
                DLevel = append(DLevel, nil)
            }
            DLevel = append(DLevel, []int{i, j})
            if k/4 == 0 {
                DLevel = append(DLevel, []int{0, 0})
                DLevel = append(DLevel, []int{0, 0})
            } else {
                DLevel = append(DLevel, []int{i - k/4, j + 1})
                DLevel = append(DLevel, []int{i + k/4, j + 1})
            }
        }
        k /= 2
        btInfo.DataLevel = append(btInfo.DataLevel, DLevel)
    }
    bt.Info = btInfo
}
 
func (bt *biTree) Info2SVG(Margin ...int) string {
    var res, Line, Color string
    info := bt.Info
    MarginX, MarginY := 0, 10
    SpaceX, SpaceY := 40, 100
    switch len(Margin) {
    case 0:
        break
    case 1:
        MarginX = Margin[0]
    case 2:
        MarginX, MarginY = Margin[0], Margin[1]
    case 3:
        MarginX, MarginY, SpaceX = Margin[0], Margin[1], Margin[2]
    default:
        MarginX, MarginY = Margin[0], Margin[1]
        SpaceX, SpaceY = Margin[2], Margin[3]
    }
    info.MarginX, info.MarginY = MarginX, MarginY
    info.SpaceX, info.SpaceY = SpaceX, SpaceY
    info.SvgWidth = Pow2(info.Height)*info.SpaceX + info.SpaceX
    info.SvgHeight = info.Height * info.SpaceY
    for i, Data := range info.Data {
        Node := "\n\t<g id=\"INDEX,M,N\">\n\t<CIRCLE/>\n\t<TEXT/>\n\t<LEAF/>\n\t</g>"
        DataStr := ""
        switch Data.(type) {
        case int:
            DataStr = strconv.Itoa(Data.(int))
        case float64:
            DataStr = strconv.FORMatFloat(Data.(float64), 'g', -1, 64)
        case string:
            DataStr = Data.(string)
        default:
            DataStr = "Error Type"
        }
        Node = strings.Replace(Node, "INDEX", strconv.Itoa(info.Index), 1)
        Node = strings.Replace(Node, "M", strconv.Itoa(info.X[i]), 1)
        Node = strings.Replace(Node, "N", strconv.Itoa(info.Y[i]), 1)
        x0, y0 := (info.X[i]+info.Width)*SpaceX+MarginX, 50+info.Y[i]*SpaceY+MarginY
        x1, y1 := x0-info.W[i]*SpaceX, y0+SpaceY-30
        x2, y2 := x0+info.W[i]*SpaceX, y0+SpaceY-30
        Color = "orange"
        if info.L[i] && info.R[i] {
            Line = XmlLine(x0-21, y0+21, x1, y1) + "\n\t" + XmlLine(x0+21, y0+21, x2, y2)
        } else if info.L[i] && !info.R[i] {
            Line = XmlLine(x0-21, y0+21, x1, y1)
        } else if !info.L[i] && info.R[i] {
            Line = XmlLine(x0+21, y0+21, x2, y2)
        } else {
            Color = "lightgreen"
        }
        Node = strings.Replace(Node, "<CIRCLE/>", XmlCircle(x0, y0, Color), 1)
        Node = strings.Replace(Node, "<TEXT/>", XmlText(x0, y0, DataStr), 1)
        if info.L[i] || info.R[i] {
            Node = strings.Replace(Node, "<LEAF/>", Line, 1)
        }
        res += Node
    }
    info.SvgXml = res
    return res
}
 
func XmlCircle(X, Y int, Color string) string {
    Radius := 30
    Circle := "<circle cx=\"" + strconv.Itoa(X) + "\" cy=\"" + strconv.Itoa(Y) +
        "\" r=\"" + strconv.Itoa(Radius) + "\" stroke=\"black\" stroke-width=" +
        "\"2\" fill=\"" + Color + "\" />"
    return Circle
}
 
func XmlText(X, Y int, DATA string) string {
    iFontSize, tColor := 20, "red"
    Text := "<text x=\"" + strconv.Itoa(X) + "\" y=\"" + strconv.Itoa(Y) +
        "\" fill=\"" + tColor + "\" font-size=\"" + strconv.Itoa(iFontSize) +
        "\" text-anchor=\"middle\" dominant-baseline=\"middle\">" + DATA + "</text>"
    return Text
}
 
func XmlLine(X1, Y1, X2, Y2 int) string {
    Line := "<line x1=\"" + strconv.Itoa(X1) + "\" y1=\"" + strconv.Itoa(Y1) +
        "\" x2=\"" + strconv.Itoa(X2) + "\" y2=\"" + strconv.Itoa(Y2) +
        "\" style=\"stroke:black;stroke-width:2\" />"
    return Line
}
 
func (bt *biTree) ShowSVG(FileName ...string) {
    var file *os.File
    var err1 error
    Head := "<svg xmlns=\"Http://www.w3.org/2000/svg\" xmlns:xlink" +
        "=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=" +
        "\"Width\" height=\"Height\">\nLINKCONTENT\n</svg>"
    Link := `<a xlink:href="https://blog.csdn.net/boysoft2002" target="_blank">
    <text x="5" y="20" fill="blue">Hann's CSDN Homepage</text></a>`
    Xml := strings.Replace(Head, "LINK", Link, 1)
    Xml = strings.Replace(Xml, "Width", strconv.Itoa(bt.Info.SvgWidth), 1)
    Xml = strings.Replace(Xml, "Height", strconv.Itoa(bt.Info.SvgHeight), 1)
    Xml = strings.Replace(Xml, "CONTENT", bt.Info.SvgXml, 1)
    svgFile := "biTree.svg"
    if len(FileName) > 0 {
        svgFile = FileName[0] + ".svg"
    }
    file, err1 = os.Create(svgFile)
    if err1 != nil {
        panic(err1)
    }
    _, err1 = io.WriteString(file, Xml)
    if err1 != nil {
        panic(err1)
    }
    file.Close()
    exec.Command("cmd", "/c", "start", svgFile).Start()
    //linux 代码:
    //exec.Command("xdg-open", svgFile).Start()
    //Mac 代码:
    //exec.Command("open", svgFile).Start()
}
 
func main() {
 
    list := []any{"*", "*", "*", "/", 5, "*", 3.14, 1, 3, nil, nil, 6, 6}
    tree := Build(list...)
    tree.TreeInfo()
    tree.Info2SVG()
    tree.ShowSVG()
 
    fmt.Println(tree.Info.Data)
    fmt.Println(tree.Info.DataLevel)
 
}

做题思路

增加一个结构biTreeInfo,在遍历二叉树时把作图要用的信息存入此结构中,方便读取信息。

type any = interface{}

type btNode struct {
    Data   any
    Lchild *btNode
    Rchild *btNode
}

type biTree struct {
    Root *btNode
    Info *biTreeInfo
}

type biTreeInfo struct {
    Data                []any
    DataLevel           [][]any
    L, R                []bool
    X, Y, W             []int
    Index, Nodes        int
    Width, Height       int
    MarginX, MarginY    int
    SpaceX, SpaceY      int
    SvgWidth, SvgHeight int
    SvgXml              string
}
//数据域类型用 type any = interface{} 自定义类型,模拟成any数据类型。

遍历二叉树获取每个结点在svg图形中的坐标,使用先序递归遍历:

func (bt *btNode) Coordinate(x, y, w int) []any {
    var res []any
    if bt != nil {
        L, R := bt.Lchild != nil, bt.Rchild != nil
        res = append(res, []any{bt.Data, L, R, x, y, w})
        res = append(res, bt.Lchild.Coordinate(x-w, y+1, w/2)...)
        res = append(res, bt.Rchild.Coordinate(x+w, y+1, w/2)...)
    }
    return res
}

二叉树的每个结点,转svg时有圆、文字、左或右直线(叶结点没有真线)。

func XmlCircle(X, Y int, Color string) string {
    Radius := 30
    Circle := "<circle cx=\"" + strconv.Itoa(X) + "\" cy=\"" + strconv.Itoa(Y) +
        "\" r=\"" + strconv.Itoa(Radius) + "\" stroke=\"black\" stroke-width=" +
        "\"2\" fill=\"" + Color + "\" />"
    return Circle
}

func XmlText(X, Y int, DATA string) string {
    iFontSize, tColor := 20, "red"
    Text := "<text x=\"" + strconv.Itoa(X) + "\" y=\"" + strconv.Itoa(Y) +
        "\" fill=\"" + tColor + "\" font-size=\"" + strconv.Itoa(iFontSize) +
        "\" text-anchor=\"middle\" dominant-baseline=\"middle\">" + DATA + "</text>"
    return Text
}

func XmlLine(X1, Y1, X2, Y2 int) string {
    Line := "<line x1=\"" + strconv.Itoa(X1) + "\" y1=\"" + strconv.Itoa(Y1) +
        "\" x2=\"" + strconv.Itoa(X2) + "\" y2=\"" + strconv.Itoa(Y2) +
        "\" style=\"stroke:black;stroke-width:2\" />"
    return Line
}

TreeInfo()写入二叉树结点信息,其中DataLevel是层序遍历的结果,也可以用它来作图。

Info2XML()就是把上述方法所得信息,转化成SVG的xml代码;

ShowSVG()生成并显示图形,svg的xml如下:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="680" height="400">
<a xlink:href="https://blog.csdn.net/boysoft2002" target="_blank">
    <text x="5" y="20" fill="blue">Hann's CSDN Homepage</text></a>
    <g id="0,0,0">
    <circle cx="320" cy="60" r="30" stroke="black" stroke-width="2" fill="orange" />
    <text x="320" y="60" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">*</text>
    <line x1="299" y1="81" x2="160" y2="130" style="stroke:black;stroke-width:2" />
    <line x1="341" y1="81" x2="480" y2="130" style="stroke:black;stroke-width:2" />
    </g>
    <g id="0,-4,1">
    <circle cx="160" cy="160" r="30" stroke="black" stroke-width="2" fill="orange" />
    <text x="160" y="160" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">*</text>
    <line x1="139" y1="181" x2="80" y2="230" style="stroke:black;stroke-width:2" />
    <line x1="181" y1="181" x2="240" y2="230" style="stroke:black;stroke-width:2" />
    </g>
    <g id="0,-6,2">
    <circle cx="80" cy="260" r="30" stroke="black" stroke-width="2" fill="orange" />
    <text x="80" y="260" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">/</text>
    <line x1="59" y1="281" x2="40" y2="330" style="stroke:black;stroke-width:2" />
    <line x1="101" y1="281" x2="120" y2="330" style="stroke:black;stroke-width:2" />
    </g>
    <g id="0,-7,3">
    <circle cx="40" cy="360" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="40" y="360" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">1</text>
    <LEAF/>
    </g>
    <g id="0,-5,3">
    <circle cx="120" cy="360" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="120" y="360" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">3</text>
    <LEAF/>
    </g>
    <g id="0,-2,2">
    <circle cx="240" cy="260" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="240" y="260" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">5</text>
    <LEAF/>
    </g>
    <g id="0,4,1">
    <circle cx="480" cy="160" r="30" stroke="black" stroke-width="2" fill="orange" />
    <text x="480" y="160" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">*</text>
    <line x1="459" y1="181" x2="400" y2="230" style="stroke:black;stroke-width:2" />
    <line x1="501" y1="181" x2="560" y2="230" style="stroke:black;stroke-width:2" />
    </g>
    <g id="0,2,2">
    <circle cx="400" cy="260" r="30" stroke="black" stroke-width="2" fill="orange" />
    <text x="400" y="260" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">*</text>
    <line x1="379" y1="281" x2="360" y2="330" style="stroke:black;stroke-width:2" />
    <line x1="421" y1="281" x2="440" y2="330" style="stroke:black;stroke-width:2" />
    </g>
    <g id="0,1,3">
    <circle cx="360" cy="360" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="360" y="360" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">6</text>
    <LEAF/>
    </g>
    <g id="0,3,3">
    <circle cx="440" cy="360" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="440" y="360" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">6</text>
    <LEAF/>
    </g>
    <g id="0,6,2">
    <circle cx="560" cy="260" r="30" stroke="black" stroke-width="2" fill="lightgreen" />
    <text x="560" y="260" fill="red" font-size="20" text-anchor="middle" dominant-baseline="middle">3.14</text>
    <LEAF/>
    </g>
</svg>

扩展

多棵二叉树同时展示,Info2SVG()可以设置起始位置

左右并列展示

    tree2 := Build("*", "*", 3.14, 6, 6)
    tree2.TreeInfo()
    tree2.Info2SVG()
    tree2.ShowSVG("tree2")
 
    //左右并列展示
    tree2.Info2SVG(tree.Info.SvgWidth, tree.Info.SpaceY)
    tree.Info.SvgXml += tree2.Info.SvgXml
    tree.Info.SvgWidth += tree2.Info.SvgWidth
    tree.ShowSVG("tree12")
    tree.Info2SVG() //恢复tree原状

上下并列展示

    //上下并列展示
    tree2.Info2SVG(tree.Info.SvgWidth-tree2.Info.SvgWidth, tree.Info.SvgHeight)
    tree.Info.SvgXml += tree2.Info.SvgXml
    tree.Info.SvgHeight += tree2.Info.SvgHeight
    tree.ShowSVG("tree123")
    tree.Info2SVG() //恢复tree原状

以上2段代码放在前文源代码的main()函数中测试

总结回顾

结点显示的代码固定了文字和圆形的大小颜色,如果读者愿意自己动手的话,可以尝试把这些要素设成参数或者增加biTreeInfo结构的属性。

到此这篇关于Go语言数据结构之二叉树可视化详解的文章就介绍到这了,更多相关Go语言 二叉树可视化内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

您可能感兴趣的文档:

--结束END--

本文标题: Go语言数据结构之二叉树可视化详解

本文链接: https://www.lsjlt.com/news/121189.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Go语言数据结构之二叉树可视化详解
    目录题目源代码做题思路扩展左右并列展示上下并列展示总结回顾题目 以图形展示任意二叉树,如下图,一个中缀表达式表示的二叉树:3.14*r²*h/3 源代码 package ...
    99+
    2022-11-11
  • C语言数据结构之二叉树详解
    目录1. 树概念及结构1.1树概念1.2树的表示2. 二叉树概念及结构2.1概念2.2数据结构中的二叉树2.3特殊的二叉树2.4二叉树的存储结构2.5二叉树的性质3. 二叉树顺序结构...
    99+
    2022-11-13
  • Go 数据结构之二叉树详情
    目录Go 语言实现二叉树定义二叉树的结构二叉树遍历创建二叉树插入值测试前言: 树可以有许多不同的形状,并且它们可以在每个节点允许的子节点数量或它们在节点内组织数据值的方式上有所不同。...
    99+
    2022-11-13
  • Go语言数据结构之二叉树必会知识点总结
    目录前言二叉树概念二叉树的性质创建二叉树树的遍历前序遍历(V-L-R)中序遍历(L-V-R)后序遍历(L-R-V)前言 如果你是一个开发人员,或多或少对树型结构都有一定的认识,我个人...
    99+
    2022-11-11
  • C语言数据结构之二叉链表创建二叉树
    目录一、思想(先序思想创建)二、创建二叉树(1)传一级参数方法(2)传二级参数方法一、思想(先序思想创建) 第一步先创建根节点,然后创建根节点左子树,开始递归创建左子树,直到递归创建...
    99+
    2022-11-13
  • 数据结构之链式二叉树详解
    目录🍏1.二叉树的遍历🍏1.1前序遍历1.2中序遍历1.3后序遍历1.4层次遍历 🍎2.链式二叉树的实现🍎2.1二叉树的创建2.2前序遍历2.3中序遍历2.4后序遍历2.5...
    99+
    2023-05-16
    C语言链式二叉树 数据结构链式二叉树 C语言 数据结构
  • 详解Java数据结构之平衡二叉树
    目录什么是二叉搜索树平衡二叉搜索树平衡二叉搜索树建树程序计算每个节点的高度计算每个节点的平衡因子合并二叉树旋转调整函数整体代码什么是二叉搜索树 简单来说,就是方便搜索的二叉树,是一种...
    99+
    2022-11-13
  • Java数据结构之二叉搜索树详解
    目录前言性质实现节点结构初始化插入节点查找节点删除节点最后前言 今天leetcode的每日一题450是关于删除二叉搜索树节点的,题目要求删除指定值的节点,并且需要保证二叉搜索树性质不...
    99+
    2022-11-13
  • C语言二叉树的概念结构详解
    目录1、树的概念及结构(了解)1.1树的概念:1.2树的表示法:2、二叉树的概念及结构2.1二叉树的概念2.2特殊的二叉树2.2二叉树的性质2.3二叉树的顺序存储2.4二叉树的链式存...
    99+
    2022-11-13
    C语言二叉树 C语言二叉树的创建
  • C语言数据结构详细解析二叉树的操作
    目录二叉树分类二叉树性质性质的使用二叉树的遍历前序遍历中序遍历后序遍历层序遍历求二叉树的节点数求二叉树叶子结点个数求二叉树的最大深度二叉树的销毁二叉树分类 满二叉树 除最后一层无任何...
    99+
    2022-11-13
  • C语言数据结构二叉树之堆的实现和堆排序详解
    目录一、本章重点二、堆2.1堆的介绍2.2堆的接口实现三、堆排序一、本章重点 堆的介绍堆的接口实现堆排序 二、堆 2.1堆的介绍 一般来说,堆在物理结构上是连续的数组结构,在逻辑结构...
    99+
    2022-11-13
  • C语言 链式二叉树结构详解原理
    目录前言二叉树节点声明二叉树的遍历构建二叉树1.前序遍历2.中序遍历3.后序遍历二叉树节点的个数二叉树叶子节点的个数二叉树第K层节点个数二叉树的高度/深度二叉树查找值为x的节点整体代...
    99+
    2022-11-12
  • 数据结构TypeScript之二叉查找树实现详解
    目录树的结构特点面向对象方法封装二叉查找树(迭代版)二叉查找树的定义构造函数基本单元:二叉查找树节点主体:二叉查找树增加节点查找节点删除节点二叉树的遍历树的结构特点 树是一种有层次...
    99+
    2023-01-30
    TypeScript数据结构二叉查找树 TypeScript数据结构
  • C语言数据结构系列篇二叉树的概念及满二叉树与完全二叉树
    链接:C语言数据结构系列之树的概念结构和常见表示方法 0x00 概念 定义:二叉树既然叫二叉树,顾名思义即度最大为2的树称为二叉树。 它的度可以为 1 也可...
    99+
    2022-11-13
  • Java数据结构之平衡二叉树的实现详解
    目录定义结点结构查找算法插入算法LL 型RR 型LR 型RL 型插入方法删除算法概述实例分析代码完整代码定义 动机:二叉查找树的操作实践复杂度由树高度决定,所以希望控制树高,左右子...
    99+
    2022-11-13
  • C++数据结构之二叉搜索树的实现详解
    目录前言介绍实现节点的实现二叉搜索树的查找二叉搜索树的插入二叉搜索树的删除总结前言 今天我们来学一个新的数据结构:二叉搜索树。 介绍 二叉搜索树也称作二叉排序树,它具有以下性质: 非...
    99+
    2022-11-13
  • C语言植物大战数据结构二叉树堆
    目录前言堆的概念创建结构体初始化结构体销毁结构体向堆中插入数据1.堆的物理结构和逻辑结构2.完全二叉树下标规律3.插入数据思路依次打印堆的值删除堆顶的值判断堆是否为空求堆中有几个元素...
    99+
    2022-11-13
  • C语言数据结构二叉树递归的方法
    本篇内容介绍了“C语言数据结构二叉树递归的方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一、二叉树的遍历算法二叉树的精髓在于遍历。遍历掌...
    99+
    2023-06-30
  • go语言数据结构之前缀树Trie
    目录介绍流程代码初始化插入查找统计以XXX开头的单词个数删除数据介绍 Trie树:又称为单词查找树,是一种树形结构,可以应用于统计字符串,会在搜索引擎系统中用于对文本的词频统计,下图...
    99+
    2022-11-13
  • Java数据结构之线索化二叉树的实现
    目录1.线索化二叉树的介绍2.线索化二叉树的基本特点3.线索化二叉树的应用案例4.前序线索化二叉树、遍历5.后序线索化二叉树1.线索化二叉树的介绍 将数列 {1, 3, 6, 8, ...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作