• 大小: 153KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-21
  • 语言: 其他
  • 标签: AVL树  红黑树  

资源简介

本人实现的 AVL树与红黑树,具有可视化界面,代码清晰。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdvancedSearchDataStructure
{
    public interface INode
    {
        // Properties
        int BF { get; }
        int Data { get; }
        INode Left { get; }
        INode Right { get; }
    }

    public class Node : INode
    {
        // Fields
        private int _bf;
        private int _data;
        private Node _left;
        private Node _right;

        // Methods
        public Node(int value)
        {
            this._data = value;
        }

        public override string ToString()
        {
            return this._data.ToString();
        }

        // Properties
        public int BF
        {
            get
            {
                return this._bf;
            }
            set
            {
                this._bf = value;
            }
        }

        public int Data
        {
            get
            {
                return this._data;
            }
            set
            {
                this._data = value;
            }
        }

        public Node Left
        {
            get
            {
                return this._left;
            }
            set
            {
                this._left = value;
            }
        }

        INode INode.Left
        {
            get
            {
                return this._left;
            }
        }

        INode INode.Right
        {
            get
            {
                return this._right;
            }
        }

        public Node Right
        {
            get
            {
                return this._right;
            }
            set
            {
                this._right = value;
            }
        }
    }

    public interface IBinaryTree
    {
        // Properties
        INode Head { get; }

        bool Insert(int value);
        bool Remove(int value);

        bool ClearTree();
    }

    public class AVLTree : IBinaryTree
    {
        // Fields
        private Node _head;

        private Node[] path = new Node[128]; //记录访问路径上的结点
        private int p; //表示当前访问到的结点在_path上的索引

        // Methods
        public bool Insert(int value)
        {
            Node newNode = new Node(value);
            //如果是空树,则新结点成为二叉排序树的根
            if (_head == null)
            {
                _head = newNode;
                _head.BF = 0;
                return true;
            }

            p = 0;
            //prev为上一次访问的结点,current为当前访问结点
            Node prev = null current = _head;
            while (true)
            {
                path[p++] = current;

                prev = current;
                if (value < current.Data)
                {
                    current = current.Left;
                    if (current == null)
                    {
                        p

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       13365  2012-05-27 00:00  RBTree2.cs
     文件        4712  2012-05-25 22:50  TreeGraphics.cs
     目录           0  2013-01-04 15:16  bin\
     目录           0  2013-01-04 15:16  bin\Debug\
     文件       27136  2012-12-07 15:35  bin\Debug\AdvancedSearchDataStructure.exe
     文件       87552  2012-12-07 15:35  bin\Debug\AdvancedSearchDataStructure.pdb
     文件       11600  2012-06-07 19:37  bin\Debug\AdvancedSearchDataStructure.vshost.exe
     文件         490  2010-03-17 22:39  bin\Debug\AdvancedSearchDataStructure.vshost.exe.manifest
     目录           0  2013-01-04 15:16  bin\Release\
     文件       22528  2012-05-25 11:34  bin\Release\AdvancedSearchDataStructure.exe
     文件       69120  2012-05-25 11:34  bin\Release\AdvancedSearchDataStructure.pdb
     目录           0  2013-01-04 15:16  obj\
     目录           0  2013-01-04 15:16  obj\x86\
     目录           0  2013-01-04 15:16  obj\x86\Debug\
     文件        2111  2012-07-24 21:09  obj\x86\Debug\AdvancedSearchDataStructure.csproj.FileListAbsolute.txt
     文件       27136  2012-12-07 15:35  obj\x86\Debug\AdvancedSearchDataStructure.exe
     文件        1154  2012-12-07 15:35  obj\x86\Debug\AdvancedSearchDataStructure.Form1.resources
     文件       87552  2012-12-07 15:35  obj\x86\Debug\AdvancedSearchDataStructure.pdb
     文件         180  2012-12-07 15:35  obj\x86\Debug\AdvancedSearchDataStructure.Properties.Resources.resources
     文件        4440  2012-05-26 23:46  obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6392  2012-12-07 15:35  obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1110  2012-12-07 15:35  obj\x86\Debug\GenerateResource.read.1.tlog
     文件        1770  2012-12-07 15:35  obj\x86\Debug\GenerateResource.write.1.tlog
     目录           0  2012-05-25 20:41  obj\x86\Debug\TempPE\
     目录           0  2013-01-04 15:16  obj\x86\Release\
     文件        1114  2012-05-23 13:11  obj\x86\Release\AdvancedSearchDataStructure.csproj.FileListAbsolute.txt
     文件       22528  2012-05-25 11:34  obj\x86\Release\AdvancedSearchDataStructure.exe
     文件         180  2012-05-25 11:34  obj\x86\Release\AdvancedSearchDataStructure.Form1.resources
     文件       69120  2012-05-25 11:34  obj\x86\Release\AdvancedSearchDataStructure.pdb
     文件         180  2012-05-25 11:34  obj\x86\Release\AdvancedSearchDataStructure.Properties.Resources.resources
     文件        2152  2012-05-23 12:54  obj\x86\Release\DesignTimeResolveAssemblyReferences.cache
............此处省略18个文件信息

评论

共有 条评论