Exemplo n.º 1
0
        private void visit(int node)
        {
            Trace.Assert(!booking[node]);
            booking[node] = true;

            foreach (Edge edge in graph.Edges(node))
            {
                int to = edge.To();
                if (!booking[to])
                {
                    if (path[to] != null)
                    {
                        if (weight[to] > weight[node] + edge.Weight())
                        {
                            weight[to] = weight[node] + edge.Weight();
                            queue.Change(to, weight[to]);
                            path[to] = edge;
                        }
                    }
                    else
                    {
                        weight[to] = weight[node] + edge.Weight();
                        queue.Insert(to, weight[to]);
                        path[to] = edge;
                    }
                }
            }
        }
Exemplo n.º 2
0
    //测试是否改变某个堆中某个数字只需要,对该数字ShiftUP 和shiftDown即可
    public void testChangeInNormalHeap(MinHeap <int> minHeap)
    {
        int index = Random.Range(1, minHeap.Size());
        int item  = 10;

        minHeap.Change(index, 10);
        minHeap.print();
    }
Exemplo n.º 3
0
        private void visit(int k)
        {
            if (visited[k])
            {
                Trace.Assert(!visited[k]);
            }
            visited[k] = true;
            foreach (Edge edge in graph.Edges(k))
            {
                if (!visited[edge.To()])
                {
                    Edge e = queue.Get(edge.To());

                    if (e == null)
                    {
                        queue.Insert(edge.To(), edge);
                    }
                    else if (e.Weight() > edge.Weight())
                    {
                        queue.Change(edge.To(), edge);
                    }
                }
            }
        }