예제 #1
0
        public int DistanciaTotal()
        {
            int d = 0;

            Caminho[] vet = Caminhos.ToArray();
            for (int i = 0; i < Caminhos.Tamanho(); i++)
            {
                d += vet[i].Distancia;
            }
            return(d);
        }
예제 #2
0
        private double Calcular()
        {
            PilhaLista <double> valores = new PilhaLista <double>();
            double a = 0, b = 0, ret = 0;

            string[] vet = posfixa.ToArray();

            foreach (string s in vet)
            {
                if (!ops.Contains(s))
                {
                    valores.Empilhar(double.Parse(s.Replace('.', ',')));
                }
                else
                {
                    a = valores.Desempilhar();
                    b = valores.Desempilhar();
                    switch (s)
                    {
                    case "^":
                        ret = Math.Pow(b, a);
                        break;

                    case "*":
                        ret = a * b;
                        break;

                    case "/":
                        if (a == 0)
                        {
                            throw new DivideByZeroException("Divisão por 0");
                        }
                        ret = b / a;
                        break;

                    case "+":
                        ret = a + b;
                        break;

                    case "-":
                        ret = b - a;
                        break;

                    default:
                        break;
                    }
                    valores.Empilhar(ret);
                }
            }
            return(valores.Desempilhar());
        }
예제 #3
0
        private void EscreverSequencia(FilaLista <string> fil)
        {
            char letra = 'A';

            string[] vet = fil.ToArray();
            foreach (string s in vet)
            {
                if (ops.Contains(s))
                {
                    lbSequencias.Text += s;
                }
                else
                {
                    lbSequencias.Text += letra++;
                }
            }
        }
예제 #4
0
        private void EscreverSequencia(FilaLista <string> fil)
        {
            char letra = 'A';

            string[] vet = fil.ToArray(); //Passa a fila para vetor
            foreach (string s in vet)
            {
                if (ops.Contains(s))        //Se for um operador
                {
                    lbSequencias.Text += s; //Exibe o operador
                }
                else //Se for um número
                {
                    lbSequencias.Text += letra++; //Exibe uma letra correspondente
                }
            }
        }