using System.Collections.Generic;

namespace PinyinModel
{
    class Graph
    {
        public class Vertex
        {
            public List<Edge> from;
            public List<Edge> to;
            public object data;
            public int id;

            public Vertex(int id)
            {
                this.from = new List<Edge>();
                this.to = new List<Edge>();
                this.data = null;
                this.id = id;
            }
        }

        public class Edge
        {
            public Vertex from;
            public Vertex to;
            public object data;

            public Edge(Vertex from, Vertex to)
            {
                this.from = from;
                this.to = to;
                this.data = null;
            }
        }

        protected Vertex[] vertex;
		protected LinkedList<Edge> edges = new LinkedList<Edge>();
        protected int vertex_count = 0;
        protected int edge_count = 0;

        public int VertexCount
        {
            get { return vertex_count; }
        }

        public int EdgeCount
        {
            get { return edge_count; }
        }

        protected void InitializeVertex()
        {
            vertex = new Vertex[vertex_count];
            for (int i = 0; i < vertex_count; i++)
            {
                vertex[i] = new Vertex(i);
            }
        }

        protected virtual Edge AddEdge(Vertex from, Vertex to)
        {
            Edge e = new Edge(from, to);
            from.to.Add(e);
            to.from.Add(e);
            edge_count++;
			edges.AddLast(e);
            return e;
        }
		
        public Vertex[] Vertexes
        {
            get { return vertex; }
        }

        public LinkedList<Edge> Edges
        {
            get { return edges; }
        }
    }
}
