Example #1
0
File: Pilha.cs Project: Scdk/OOP
 private bool isVazia(NohPilha noh)
 {
     if (noh == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
File: Pilha.cs Project: Scdk/OOP
 public void desempilhar()
 {
     if (isVazia(topo))
     {
         Console.WriteLine("A pilha está vazia.");
     }
     else
     {
         topo = topo.getNext();
         Console.WriteLine("Desempilhado com sucesso.");
     }
 }
Example #3
0
File: Pilha.cs Project: Scdk/OOP
 public void imprimir()
 {
     if (isVazia(topo))
     {
         Console.WriteLine("A pilha está vazia.");
     }
     else
     {
         NohPilha topoAux = new NohPilha();
         topoAux = topo;
         Console.WriteLine("Pilha: ");
         for (int i = 0; topoAux != null; i++)
         {
             Console.WriteLine(i + 1 + "°: " + topoAux.getInfo() + "\n");
             topoAux = topoAux.getNext();
         }
     }
 }
Example #4
0
File: Form1.cs Project: Scdk/OOP
        private void testador()
        {
            bool  flag = false;
            Pilha p1   = new Pilha();

            for (int i = 0; i < textBox1.TextLength; i++)
            {
                if (textBox1.Text[i] == '{' || textBox1.Text[i] == '[' || textBox1.Text[i] == '(')
                {
                    p1.empilhar(textBox1.Text[i]);
                }
                else if (textBox1.Text[i] == '}')
                {
                    if (p1.getTopo() != null && p1.getTopo().getInfo() == '{')
                    {
                        p1.desempilhar();
                    }
                    else
                    {
                        flag = true;
                        break;
                    }
                }
                else if (textBox1.Text[i] == ']')
                {
                    if (p1.getTopo() != null && p1.getTopo().getInfo() == '[')
                    {
                        p1.desempilhar();
                    }
                    else
                    {
                        flag = true;
                        break;
                    }
                }
                else if (textBox1.Text[i] == ')')
                {
                    if (p1.getTopo() != null && p1.getTopo().getInfo() == '(')
                    {
                        p1.desempilhar();
                    }
                    else
                    {
                        flag = true;
                        break;
                    }
                }
                else
                {
                    continue;
                }
            }
            NohPilha topoAux = new NohPilha();

            topoAux = p1.getTopo();
            for (int i = 0; topoAux != null; i++)
            {
                if (topoAux.getInfo() == '{' || topoAux.getInfo() == '[' || topoAux.getInfo() == '(')
                {
                    flag = true;
                }
                topoAux = topoAux.getNext();
            }
            if (flag)
            {
                MessageBox.Show("A expressão matemática está incorreta");
            }
            else
            {
                MessageBox.Show("A expressão matemática está correta");
            }
        }
Example #5
0
 public void setNext(NohPilha novoNext)
 {
     next = novoNext;
 }
Example #6
0
 public NohPilha(char novoInfo, NohPilha novoNext)
 {
     info = novoInfo;
     next = novoNext;
 }
Example #7
0
File: Pilha.cs Project: Scdk/OOP
        public void empilhar(char novoInfo)
        {
            NohPilha novoNoh = new NohPilha(novoInfo, topo);

            topo = novoNoh;
        }