Sunteți pe pagina 1din 3

EJERCICIO DE COLAS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Cola
{
public partial class Form1 : Form
{
ClaseCola cola1 = new ClaseCola();
public Form1()
{
InitializeComponent();
}

private void btnagregar_Click(object sender, EventArgs e)


{

listBox1.Items.Add(cola1.Insertar(Convert.ToInt32(textBox1.Text)));

private void btnextrae_Click(object sender, EventArgs e)


{

cola1.Extraer();
if (listBox1.Items.Count > 0)
{
listBox1.Items.RemoveAt(0);
}
}

private void btnmostrar_Click(object sender, EventArgs e)


{
label1.Text = Convert.ToString(cola1.imprimir());

}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Cola
{
class ClaseCola
{
class Nodo
{
public int info;
public Nodo sig;
}

private Nodo raiz,fondo;

public ClaseCola()
{
raiz=null;
fondo=null;
}

public bool Vacia ()


{
if (raiz == null)
return true;
else
return false;
}

public int Insertar (int info)


{
Nodo nuevo;
nuevo = new Nodo ();
nuevo.info = info;
nuevo.sig = null;
if (Vacia ())
{
raiz = nuevo;
fondo = nuevo;
}
else
{
fondo.sig = nuevo;
fondo = nuevo;
}
return info;
}

public int Extraer ()


{
if (!Vacia ())
{
int informacion = raiz.info;
if (raiz == fondo)
{
raiz = null;
fondo = null;
}
else
{
raiz = raiz.sig;
}
return informacion;
}
else
return 0;
}

public int imprimir()


{
Nodo reco = raiz;
string valores="";
while (reco != null)
{
valores = valores + Convert.ToString(reco.info);
reco = reco.sig;

}
return Convert.ToInt32(valores);

S-ar putea să vă placă și