Exemple #1
0
 public void popNumber(int a)
 {
     if (!isEmpty())
     {
         Pilha p      = new Pilha();
         int   verify = 0;
         while (verify != a)
         {
             if (topo.Data == a)
             {
                 pop();
                 verify = a;
             }
             else
             {
                 p.push(topo.Data);
                 topo = topo.Next;
             }
         }
         while (p.topo != null)
         {
             push(p.topo.Data);
             p.topo = p.topo.Next;
         }
     }
 }
Exemple #2
0
        public void push(int n)
        {
            //Primeira coisa: criar um objeto da classe NohPilha
            NohPilha novo = new NohPilha(n);

            //Segunda coisa: encadear esse novo noh na Pilha
            novo.Next = topo;
            topo      = novo;
        }//Fim do metodo push
Exemple #3
0
        }//Fim do metodo push

        public string pop()
        {
            if (!isEmpty())
            {
                int temp = topo.Data;
                topo = topo.Next;
                return(Convert.ToString(temp));
            }
            else
            {
                return("pilha vazia");
            }
        }
Exemple #4
0
        }//Fim do metodo push

        public int pop()
        {
            if (isEmpty())
            {
                Console.WriteLine("Pilha Vazia - Impossivel Retirar!!");
                return(0);
            }
            else
            {
                int temp = topo.Data;
                topo = topo.Next;
                return(temp);
            }
        }
Exemple #5
0
        public string print()
        {
            string text = "";

            if (!isEmpty())
            {
                NohPilha temp = topo;
                while (temp != null)
                {
                    text += (Convert.ToString(temp.Data) + " ");
                    temp  = temp.Next;
                }
            }
            return(text);
        }
Exemple #6
0
        public Pilha inverte()
        {
            Pilha a = new Pilha();

            if (!isEmpty())
            {
                NohPilha temp = topo;
                while (temp != null)
                {
                    a.push(temp.Data);
                    temp = temp.Next;
                }
                a.print();
            }
            return(a);
        }
Exemple #7
0
        public int Menor()
        {
            int aux1 = topo.Data;

            if (!isEmpty())
            {
                NohPilha temp = topo;
                while (temp != null)
                {
                    if (temp.Data < aux1)
                    {
                        aux1 = temp.Data;
                    }
                    temp = temp.Next;
                }
            }
            return(aux1);
        }
Exemple #8
0
 public String Menor()
 {
     if (!isEmpty())
     {
         NohPilha temp = topo;
         int      aux1 = temp.Data;
         while (temp != null)
         {
             if (temp.Data < aux1)
             {
                 aux1 = temp.Data;
             }
             temp = temp.Next;
         }
         return(Convert.ToString(aux1));
     }
     else
     {
         return("pilha vazia");
     }
 }
Exemple #9
0
 //Metodos
 public Pilha()
 {
     topo = null;
 }
Exemple #10
0
 public NohPilha(int n, NohPilha nextNoh)
 {
     data = n;
     next = nextNoh;
 }
Exemple #11
0
 public NohPilha(int n)
 {
     data = n;
     next = null;
 }
Exemple #12
0
        private NohPilha next; //auto referenciamento

        //Metodos
        public NohPilha() //construtor default
        {
            next = null;
        }