Example #1
0
 public void Push(Nod n)
 {
     dim++;
     Nod[] aux = new Nod[dim];
     aux[0] = n;
     for (int i = 1; i < dim; i++)
     {
         aux[i] = values[i - 1];
     }
     values = aux;
 }
Example #2
0
        public Nod Pop()
        {
            dim--;
            Nod[] aux = new Nod[dim];
            for (int i = 0; i < dim; i++)
            {
                aux[i] = values[i];
            }
            Nod a = values[dim];

            values = aux;
            return(a);
        }
Example #3
0
        public static List <Point> Lee(Point start, Point end)
        {
            List <Point> path = new List <Point>();
            Coada        A    = new Coada();

            A.Push(new Nod(start.X, start.Y, 1));
            int[,] Aux = new int[n, m];

            while (A.dim != 0)
            {
                Nod curent = A.Pop();
                if (curent.i - 1 >= 0 && Aux[curent.i - 1, curent.j] == 0)
                {
                    A.Push(new Nod(curent.i - 1, curent.j, curent.val + 1));
                    Aux[curent.i - 1, curent.j] = curent.val + 1;
                }
                if (curent.j - 1 >= 0 && Aux[curent.i, curent.j - 1] == 0)
                {
                    A.Push(new Nod(curent.i, curent.j - 1, curent.val + 1));
                    Aux[curent.i, curent.j - 1] = curent.val + 1;
                }
                if (curent.i + 1 < n && Aux[curent.i + 1, curent.j] == 0)
                {
                    A.Push(new Nod(curent.i + 1, curent.j, curent.val + 1));
                    Aux[curent.i + 1, curent.j] = curent.val + 1;
                }
                if (curent.j + 1 < m && Aux[curent.i, curent.j + 1] == 0)
                {
                    A.Push(new Nod(curent.i, curent.j + 1, curent.val + 1));
                    Aux[curent.i, curent.j + 1] = curent.val + 1;
                }
            }

            if (Aux[end.X, end.Y] == 0)
            {
                return(null);
            }
            path.Add(end);
            Point crt = end;

            while (Aux[crt.X, crt.Y] > 2)
            {
                if (crt.X - 1 >= 0 && Aux[crt.X - 1, crt.Y] == Aux[crt.X, crt.Y] - 1)
                {
                    crt.X--;
                }
                else if (crt.Y - 1 >= 0 && Aux[crt.X, crt.Y - 1] == Aux[crt.X, crt.Y] - 1)
                {
                    crt.Y--;
                }
                else if (crt.X + 1 < n && Aux[crt.X + 1, crt.Y] == Aux[crt.X, crt.Y] - 1)
                {
                    crt.X++;
                }
                else if (crt.Y + 1 < m && Aux[crt.X, crt.Y + 1] == Aux[crt.X, crt.Y] - 1)
                {
                    crt.Y++;
                }
                path.Add(new Point(crt.X, crt.Y));
            }
            return(path);
        }