示例#1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            VertexDistance otherVertexDistance = obj as VertexDistance;

            if (otherVertexDistance == null)
            {
                throw new ArgumentException("Object is not a VertexDistance");
            }

            return(this.Distance.CompareTo(otherVertexDistance.Distance));
        }
示例#2
0
        public override ShortestPathResult Find(string source)
        {
            Clear();
            Initialize(source);

            _queue.Push(new VertexDistance(source, 0));

            while (!_queue.IsEmpty)
            {
                VertexDistance current = _queue.Pop();

                if (!_visited.Contains(current.Vertex))
                {
                    _visited.Insert(current.Vertex);
                    foreach (Edge e in _graph.GetNeighborsAsEdges(current.Vertex))
                    {
                        Relax(current.Vertex, e);
                    }
                }
            }

            return(new ShortestPathResult(_previous, _distance, source, _hasNegativeCycle));
        }