⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 narytree.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;

    [Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng."), Version("$Id: NaryTree.cs,v 1.3 2001/09/11 12:04:04 brpreiss Exp $")]
    public class NaryTree : AbstractTree
    {
        public NaryTree(int degree)
        {
            this.key = null;
            this.degree = degree;
            this.subtree = null;
        }

        public NaryTree(int degree, object key)
        {
            this.key = key;
            this.degree = degree;
            this.subtree = new NaryTree[degree];
            for (int num1 = 0; num1 < degree; num1++)
            {
                this.subtree[num1] = new NaryTree(degree);
            }
        }

        public void AttachKey(object obj)
        {
            if (!this.IsEmpty)
            {
                throw new InvalidOperationException();
            }
            this.key = obj;
            this.subtree = new NaryTree[this.degree];
            for (int num1 = 0; num1 < this.degree; num1++)
            {
                this.subtree[num1] = new NaryTree(this.degree);
            }
        }

        public void AttachSubtree(int i, NaryTree t)
        {
            if (this.IsEmpty || !this.subtree[i].IsEmpty)
            {
                throw new InvalidOperationException();
            }
            this.subtree[i] = t;
        }

        public override int CompareTo(object arg)
        {
            throw new MethodNotImplementedException();
        }

        public object DetachKey()
        {
            if (!this.IsLeaf)
            {
                throw new InvalidOperationException();
            }
            object obj1 = this.key;
            this.key = null;
            this.subtree = null;
            return obj1;
        }

        private NaryTree DetachSubtree(int i)
        {
            if (this.IsEmpty)
            {
                throw new InvalidOperationException();
            }
            NaryTree tree1 = this.subtree[i];
            this.subtree[i] = new NaryTree(this.degree);
            return tree1;
        }

        public override Tree GetSubtree(int i)
        {
            if (this.IsEmpty)
            {
                throw new InvalidOperationException();
            }
            return this.subtree[i];
        }

        public static void Main()
        {
            NaryTree tree1 = new NaryTree(3, 1);
            tree1.AttachSubtree(0, new NaryTree(3, 2));
            tree1.AttachSubtree(1, new NaryTree(3, 3));
            tree1.AttachSubtree(2, new NaryTree(3, 4));
            AbstractTree.TestTree(tree1);
        }

        public override void Purge()
        {
            this.key = null;
            this.subtree = null;
        }


        public override int Degree
        {
            get
            {
                return (this.IsEmpty ? 0 : this.degree);
            }
        }

        public override bool IsEmpty
        {
            get
            {
                return (this.key == null);
            }
        }

        public override bool IsLeaf
        {
            get
            {
                if (this.IsEmpty)
                {
                    return false;
                }
                for (int num1 = 0; num1 < this.degree; num1++)
                {
                    if (!this.subtree[num1].IsEmpty)
                    {
                        return false;
                    }
                }
                return true;
            }
        }

        public override object Key
        {
            get
            {
                if (this.IsEmpty)
                {
                    throw new InvalidOperationException();
                }
                return this.key;
            }
        }


        protected int degree;
        protected object key;
        protected NaryTree[] subtree;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -