using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace EXAMEN_UIII_2._1__VISUAL_
{
class Pila
{
char[] vec;
int tam;
int tope;
bool vacia, llena;
public Pila(int
tamaño)
{
vec = new char[tamaño];
tam = tamaño;
tope = 0;
vacia = true;
llena = false;
}
public void push(char valor)
{
vacia = false;
vec[tope++] = valor;
if
(tope == tam)
llena = true;
}
public
char pop()
{
if
(--tope == 0)
vacia = true;
llena = false;
return
vec[tope];
}
public
bool estavacia
{
get
{
return
vacia;
}
}
public
int Tope
{
get
{ return tope; }
}
public
int Max
{
get
{ return vec.Length; }
}
public
bool esta_llena()
{
return
llena;
}
public
char this[int index]
{
get
{ return vec[index]; }
}
//aqui intente complicarme la vida jajaja xD
public bool
validarbien(string cadena)
{
char[] aux = cadena.ToCharArray();
for (int i = 0; i < cadena.Length; i++)
{
push(aux[i]);
}
//validamos
int con1 = 0, con2 = 0, con3 = 0, con4 =
0, con5 = 0, con6 = 0;
int j = 0;
while
(!estavacia)
{
aux[j] = pop();
if
(aux[j] == 40)
{
con1++;
}
else
if (aux[j] == 41)
con2++;
else
if (aux[j] == 91)
con3++;
else
if (aux[j] == 93)
con4++;
else
if (aux[j] == 123)
con5++;
else
if (aux[j] == 125)
con6++;
j++;
}
if (con1 == con2 && con3 == con4
&& con5 == con6)
return true;
else
return
false;
}
}
}
===================================
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace EXAMEN_UIII_2._1__VISUAL_
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void butVerificar_Click(object sender, EventArgs e)
{
string cadena = Convert.ToString(textInsertar.Text);
Pila pila = new Pila(cadena.Length);
labelResultado.Text=/*"validamos bien :
" +*/ Convert.ToString(
pila.validarbien(cadena));
}
}
}
No hay comentarios:
Publicar un comentario