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

📄 abstractgraph.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    return this.count;
                }
            }


            private int count;
        }

        protected class GraphEdge : ComparableObject, Edge, IComparable
        {
            public GraphEdge(AbstractGraph graph, int v0, int v1, object weight)
            {
                this.graph = graph;
                this.v0 = v0;
                this.v1 = v1;
                this.weight = weight;
            }

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

            public override int GetHashCode()
            {
                int num1 = (this.v0 * this.graph.numberOfVertices) + this.v1;
                if (this.weight != null)
                {
                    num1 += this.weight.GetHashCode();
                }
                return num1;
            }

            public virtual Vertex MateOf(Vertex v)
            {
                if (v.Number != this.v0)
                {
                    if (v.Number != this.v1)
                    {
                        throw new ArgumentException("invalid vertex");
                    }
                    return this.graph.vertex[this.v0];
                }
                return this.graph.vertex[this.v1];
            }

            public override string ToString()
            {
                StringBuilder builder1 = new StringBuilder();
                builder1.Append("Edge {" + this.v0);
                if (this.IsDirected)
                {
                    builder1.Append("->" + this.v1);
                }
                else
                {
                    builder1.Append("--" + this.v1);
                }
                if (this.weight != null)
                {
                    builder1.Append(", weight = " + this.weight);
                }
                builder1.Append("}");
                return builder1.ToString();
            }


            public virtual bool IsDirected
            {
                get
                {
                    return this.graph.IsDirected;
                }
            }

            public virtual Vertex V0
            {
                get
                {
                    return this.graph.vertex[this.v0];
                }
            }

            public virtual Vertex V1
            {
                get
                {
                    return this.graph.vertex[this.v1];
                }
            }

            public virtual object Weight
            {
                get
                {
                    return this.weight;
                }
            }


            protected AbstractGraph graph;
            protected int v0;
            protected int v1;
            protected object weight;
        }

        protected class GraphVertex : ComparableObject, Vertex, IComparable
        {
            public GraphVertex(AbstractGraph graph, int number, object weight)
            {
                this.graph = graph;
                this.number = number;
                this.weight = weight;
            }

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

            public override int GetHashCode()
            {
                int num1 = this.number;
                if (this.weight != null)
                {
                    num1 += this.weight.GetHashCode();
                }
                return num1;
            }

            public override string ToString()
            {
                StringBuilder builder1 = new StringBuilder();
                builder1.Append("Vertex {" + this.number);
                if (this.weight != null)
                {
                    builder1.Append(", weight = " + this.weight);
                }
                builder1.Append("}");
                return builder1.ToString();
            }


            public IEnumerable EmanatingEdges
            {
                get
                {
                    return this.graph.GetEmanatingEdges(this.number);
                }
            }

            public IEnumerable IncidentEdges
            {
                get
                {
                    return this.graph.GetIncidentEdges(this.number);
                }
            }

            public virtual int Number
            {
                get
                {
                    return this.number;
                }
            }

            public IEnumerable Predecessors
            {
                get
                {
                    return new Enumerable(new PredecessorEnumerator(this));
                }
            }

            public IEnumerable Successors
            {
                get
                {
                    return new Enumerable(new Opus6.AbstractGraph.GraphVertex.SuccessorEnumerator(this));
                }
            }

            public virtual object Weight
            {
                get
                {
                    return this.weight;
                }
            }


            protected AbstractGraph graph;
            protected int number;
            protected object weight;


            private class PredecessorEnumerator : IEnumerator
            {
                internal PredecessorEnumerator(AbstractGraph.GraphVertex vertex)
                {
                    this.vertex = vertex;
                    this.edges = vertex.IncidentEdges.GetEnumerator();
                }

                public bool MoveNext()
                {
                    return this.edges.MoveNext();
                }

                public void Reset()
                {
                    this.edges.Reset();
                }


                public object Current
                {
                    get
                    {
                        return ((Edge) this.edges.Current).MateOf(this.vertex);
                    }
                }


                private IEnumerator edges;
                private AbstractGraph.GraphVertex vertex;
            }

            private class SuccessorEnumerator : IEnumerator
            {
                internal SuccessorEnumerator(AbstractGraph.GraphVertex vertex)
                {
                    this.vertex = vertex;
                    this.edges = vertex.EmanatingEdges.GetEnumerator();
                }

                public bool MoveNext()
                {
                    return this.edges.MoveNext();
                }

                public void Reset()
                {
                    this.edges.Reset();
                }


                public object Current
                {
                    get
                    {
                        return ((Edge) this.edges.Current).MateOf(this.vertex);
                    }
                }


                private IEnumerator edges;
                private AbstractGraph.GraphVertex vertex;
            }
        }

        private class PrintingVisitor : AbstractVisitor
        {
            public void Finish()
            {
                Opus6.Console.WriteLine();
                this.comma = false;
            }

            public override void Visit(object obj)
            {
                if (this.comma)
                {
                    Opus6.Console.Write(", ");
                }
                Opus6.Console.Write(obj);
                this.comma = true;
            }


            private bool comma;
        }

        private class ToStringVisitor : AbstractVisitor
        {
            public ToStringVisitor()
            {
                this.s = new StringBuilder();
            }

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

            public override void Visit(object obj)
            {
                Vertex vertex1 = (Vertex) obj;
                this.s.Append(vertex1 + "\r\n");
                foreach (Edge edge1 in vertex1.EmanatingEdges)
                {
                    this.s.Append("    " + edge1 + "\r\n");
                }
            }


            private StringBuilder s;
        }

        private class VertexEnumerator : IEnumerator
        {
            internal VertexEnumerator(AbstractGraph graph)
            {
                this.v = -1;
                this.graph = graph;
            }

            public bool MoveNext()
            {
                this.v++;
                if (this.v == this.graph.numberOfVertices)
                {
                    this.v = -1;
                }
                return (this.v >= 0);
            }

            public void Reset()
            {
                this.v = -1;
            }


            public object Current
            {
                get
                {
                    if (this.v < 0)
                    {
                        throw new InvalidOperationException();
                    }
                    return this.graph.vertex[this.v];
                }
            }


            private AbstractGraph graph;
            protected int v;
        }
    }
}

⌨️ 快捷键说明

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