예제 #1
0
 public static void Main()
 {
     heap obj = new heap();
     Console.WriteLine("Elements Before sorting : ");
     obj.print();
     obj.hsort();
     Console.WriteLine("Elements After sorting : ");
     obj.print();
     Console.Read();s
 }
예제 #2
0
    public static void Main()
    {
        List<int> myList = new List<int>(new int[] {2,5,1,1990,0,6,9,3,7,7,4,8,500,678});
        int myLen = myList.Count;
        heap myHeap = new heap(myList, myLen);

        Console.WriteLine("Original: {0}",myHeap.printList());
        myHeap.hsort();
        Console.WriteLine("Sorted: {0}",myHeap.printList());
    }
예제 #3
0
        static void Main(string[] args)
        {
            List <int> array = new List <int>()
            {
                4, 1, 5, 10, 3, 7, 888, 9, -10, 299
            };

            Console.WriteLine("Original array: ");
            print(array.ToArray());
            heap minHeap = new heap(array);

            Console.WriteLine("Heap / Priority Queue: ");
            print(minHeap.heapArray.ToArray());
        }
예제 #4
0
    IEnumerator findPath(Vector3 startPos, Vector3 targetPos)
    {
        Stopwatch sw = new Stopwatch ();
        sw.Start ();

        Vector3[] waypoints = new Vector3[0];
        bool pathSuccessful = false;

        node startNode = mainGrid.nodeFromWorldPoint (startPos);
        node targetNode = mainGrid.nodeFromWorldPoint (targetPos);

        if (targetNode.walkable)
        {
            heap<node> openSet = new heap<node> (mainGrid.maxSize);
            HashSet<node> closedSet = new HashSet<node> ();
            openSet.add (startNode);

            while (openSet.count > 0)
            {
                node currentNode = openSet.removeFirst ();

                closedSet.Add (currentNode);

                if (currentNode == targetNode)
                {
                    sw.Stop ();

                    ////print ("path found in: " + sw.ElapsedMilliseconds + " ms");

                    pathSuccessful = true;
                    break;
                }

                foreach (node neighbour in mainGrid.getNeighbours(currentNode)) {

                        if (!neighbour.walkable || closedSet.Contains (neighbour)) {
                            continue;
                        }

                        int newMovementCostToNeighbour = currentNode.gCost + getDistance (currentNode, neighbour);

                        if (newMovementCostToNeighbour < neighbour.gCost || !openSet.contains (neighbour)) {
                            neighbour.gCost = newMovementCostToNeighbour;
                            neighbour.hCost = getDistance (neighbour, targetNode);
                            neighbour.parent = currentNode;

                            if (!openSet.contains (neighbour)) {
                                openSet.add (neighbour);

                            } else {
                                openSet.updateItem (neighbour);
                            }
                        }
                    }
                }
            }

            yield return null;
            if (pathSuccessful)
            {
                waypoints = retracePath (startNode, targetNode);
            }
            prm.finishedProcessingPath (waypoints, pathSuccessful);
    }
예제 #5
0
파일: SpanHeap.cs 프로젝트: nasa03/NoAlloq
 ref var siftCell = ref Cell(heap, sift);