public static List <T> YEETSort(List <T> yeet)
        {
            HeapTree <T> tree = new HeapTree <T>(true);

            for (int i = 0; i < yeet.Count; i++)
            {
                tree.Insert(yeet[i]);
            }
            List <T> yeeter = new List <T>();

            for (int i = 0; i < yeet.Count; i++)
            {
                yeeter.Add(tree.Pop());
            }
            return(yeeter);
        }
Example #2
0
        //Make an A* function that returns a Stack<Point> which will represent the INDICIES to take to get to the end point
        //The A* function will take in a Point for start and a Point for ending representing the INDICIES
        public Stack <Point> Astar(Point start, Point end, bool includeDiagonals)
        {
            //Step 1:
            for (int y = 0; y < grid.GetLength(0); y++)
            {
                for (int x = 0; x < grid.GetLength(1); x++)
                {
                    grid[y, x].Reset();
                }
            }


            //Step 2:
            grid[start.Y, start.X].Distance      = 0;
            grid[start.Y, start.X].FinalDistance = Manhattan(grid[start.Y, start.X], grid[end.Y, end.X]);
            HeapTree <Node> heapTree = new HeapTree <Node>(true);

            heapTree.Insert(grid[start.Y, start.X]);


            //Step 3:
            while (heapTree.Count > 0)
            {
                Node temp = heapTree.Pop();

                var Neighbors = neighbors(temp, includeDiagonals);
                for (int i = 0; i < Neighbors.Count; i++)
                {
                    if (Neighbors[i].Wall)
                    {
                        continue;
                    }

                    double tentative = temp.Distance + Weight(temp, Neighbors[i]);

                    if (tentative < Neighbors[i].Distance)
                    {
                        Neighbors[i].Distance      = tentative;
                        Neighbors[i].FinalDistance = tentative + Manhattan(Neighbors[i], grid[end.Y, end.X]);
                        Neighbors[i].Founder       = temp;
                        Neighbors[i].Visited       = false;
                    }

                    if (Neighbors[i].Visited == false && !heapTree.Contains(Neighbors[i]))
                    {
                        heapTree.Insert(Neighbors[i]);
                    }
                }
                temp.Visited = true;

                if (grid[end.Y, end.X].Visited)
                {
                    break;
                }


                //WE DO NOT NEED AN ACTUAL GRAPH CLASS
                //THE WAY WE WILL GET NEIGHBORS IS DYNAMICALLY

                //EVERYTIME U POP, YOU WILL HAVE A FUNCTION THAT TAKES IN A NODE
                //AND RETURNS A List<Node> which are its neighbors
            }

            //make a stack following from the end's founder back to the start
            Stack <Point> stack = new Stack <Point>();

            while (end != start)
            {
                stack.Push(new Point(end.X, end.Y));
                end = grid[end.Y, end.X].Founder.index;
            }

            stack.Push(start);

            return(stack);
        }