Funcionamiento de pilas,colas y listas

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 Estructura
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_array_Click(object sender, EventArgs e)
        {
            Form2 Formulario = new Form2();
            Formulario.Show();

            this.Hide();
        }

        private void button_pila_Click(object sender, EventArgs e)
        {
            Form3 Formulari = new Form3();
            Formulari.Show();
            this.Hide();
        }

        private void button_cola_Click(object sender, EventArgs e)
        {
            Form4 Formular = new Form4();
            Formular.Show();
            this.Hide();
        }

        private void button_lista_Click(object sender, EventArgs e)
        {
            Form5 Formula = new Form5();
            Formula.Show();
            this.Hide();
        }

        private void button_ayuda_Click(object sender, EventArgs e)
        {
            Form6 Formul = new Form6();
            Formul.Show();
            this.Hide();
        }

        private void button_salir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


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;
using System.Xml;
namespace Estructura
{
    public partial class Form2 : Form
    {
        DataSet dsDatos = new DataSet("Datos");
        string[] dato = new String[1];
        int longitud = 0;
        int i = 0;
        public Form2()
        {
            InitializeComponent();
            dsDatos.ReadXml(Application.StartupPath + "\\Datos.xml");

            dataGridView1.DataSource = dsDatos;
            dataGridView1.DataMember = "arreglos";
        }

        private void button_agregra_Click(object sender, EventArgs e)
        {

            if (textBox_Insertar.Text != "")
            {
                //Agrega un fila al Arreglo

                longitud++;


                //redimenciona la longitud del arreglo
                Array.Resize(ref dato, longitud);
                //asigna elementos al arreglo
                dato[longitud - 1] = textBox_Insertar.Text;

                String cadena = "";
                for (int i = 0; i < dato.Length; i++)
                {
                    if (cadena.Length == 0)
                    {

                        cadena = dato[i];


                    }
                    else
                    {
                        cadena = cadena + "\n" + dato[i];


                    }
                }
                dsDatos.Tables["arreglos"].Rows.Add(cadena);

                textBox_Insertar.Text = "";
                MessageBox.Show("Agregado");

            }
            else
            {
                MessageBox.Show("Por favor introduzca la información que desea agregar");
            }

        }
        private void Form2_Load(object sender, EventArgs e)
        {
          
            
        }

        private void button_borrar_Click(object sender, EventArgs e)
        {
            try
            {
                for (i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Selected == true)
                    {
                        dsDatos.Tables["arreglos"].Rows.RemoveAt(i);
                        MessageBox.Show("Ha sido elimidado.");

                    }
                   
                }
            }
            catch
            {
                MessageBox.Show("No se ha eliminado.");
            }
        }

        private void button_guardar_Click(object sender, EventArgs e)
        {
            this.BindingContext[dsDatos, "arreglos"].EndCurrentEdit();
            this.BindingContext[dsDatos, "arreglos"].AddNew();
            dsDatos.WriteXml("Datos.xml");
            dsDatos.Clear();

        }

        private void button_cargar_Click(object sender, EventArgs e)
        {
            XmlDataDocument dsDatos = new XmlDataDocument();
            dsDatos.DataSet.ReadXml(Application.StartupPath + "\\Datos.xml");

            dataGridView1.DataSource = dsDatos.DataSet;
            dataGridView1.DataMember = "arreglos";
        }

        private void button_atras_Click(object sender, EventArgs e)
        {
            Form1 Formulario = new Form1();
            Formulario.Show();
            this.Hide();
        }
    }
}
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;
using System.Xml;
namespace Estructura
{
    public partial class Form3 : Form
    {
        DataSet dsDatos = new DataSet();
        static Stack<string> PilaString;
        public Form3()
        {
            try
            {
                InitializeComponent();
                PilaString = new Stack<string>();
                dsDatos.ReadXml(Application.StartupPath + "\\Datos.xml");
                dataGridView1.DataSource = dsDatos;
                dataGridView1.DataMember = "pila";
            }
            catch
            {
            }
        }

        private void button_agregra_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox_Insertar.Text != "")
                {
                    PilaString.Push(textBox_Insertar.Text);
                    string[] row = new string[] { textBox_Insertar.Text };
                    dsDatos.Tables["pila"].Rows.Add(row);
                    textBox_Insertar.Text = "";

                    // dsDatos.Tables["pila"].Rows.Add(PilaString.Peek().ToString());
                    MessageBox.Show("Agregado");

                    //PilaString.Push(textBox_Insertar.Text);
                    //dsDatos.Tables["pila"].Rows.Add(PilaString.Peek().ToString());
                    //MessageBox.Show("Agregado");
                }
                else
                {
                    MessageBox.Show("Introduzca el elemento a agregar");
                }
            }
            catch
            {
                MessageBox.Show("jum!");
            }
        }

        private void Form3_Load(object sender, EventArgs e)
        {
          
            
        }

        private void button_borrar_Click(object sender, EventArgs e)
        {

            //PilaString.Clear();
            //            int nRows = dsDatos.Tables["pila"].Rows.Count;
            //            string strRows = nRows.ToString();
            //            string strTemp;                        
            //            for (int i = 0; i < nRows; i++)
            //            {
            //                strTemp = dsDatos.Tables["pila"].Rows[i]["ele"].ToString();
            //                PilaString.Push(int.Parse(strTemp));
            //            }
       
        try
        {

            
            {
                if (dsDatos.Tables.Count != 0)
                {
                  textBox_Insertar.Text = PilaString.Pop().ToString();
                    dsDatos.Tables["pila"].Rows.RemoveAt(PilaString.Count);

                }

            }
           
            //if (PilaString.Count != 0)
            //{
               // PilaString.Pop(dsDatos);

               // dsDatos.Tables["pila"].Rows.RemoveAt(PilaString.Count);
            //}
            //else
            //{

                //  dsDatos.Tables["pila"].Rows.RemoveAt(PilaString.Count);
               // MessageBox.Show("La pila está vacía");
            //}
        }
        catch
        {
            MessageBox.Show("Error");
        }
        }

       

        private void button_guardar_Click(object sender, EventArgs e)
        {
            try
            {
                this.BindingContext[dsDatos, "pila"].EndCurrentEdit();
                this.BindingContext[dsDatos, "pila"].AddNew();
                //dsDatos.WriteXml("Datos.xml");
                dsDatos.WriteXml(Application.StartupPath + "\\Datos.xml");
                dsDatos.Clear();
            }
            catch
            {
                MessageBox.Show("Se borró el lista de la bd");
            }
        }

        private void button_cargar_Click(object sender, EventArgs e)
        {
            try
            {
                XmlDataDocument dsDatos = new XmlDataDocument();
                dsDatos.DataSet.ReadXml(Application.StartupPath + "\\Datos.xml");

                dataGridView1.DataSource = dsDatos.DataSet;
                dataGridView1.DataMember = "pila";
            }
            catch
            {

            }
        }

        private void button_atras_Click(object sender, EventArgs e)
        {
            Form1 Formulario = new Form1();
            Formulario.Show();
            this.Hide();
        }
    }
}




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;
using System.Xml;
namespace Estructura
{
    public partial class Form4 : Form
    {
        static Queue<string> Cola;
        DataSet dsDatos = new DataSet("Datos");
        public Form4()
        {
            try
            {
                InitializeComponent();
                Cola = new Queue<string>();
                dsDatos.ReadXml(Application.StartupPath + "\\Datos.xml");
                dataGridView1.DataSource = dsDatos;
                dataGridView1.DataMember = "cola";
            }
            catch
            {

            }
        }

        private void button_agregra_Click(object sender, EventArgs e)
        {
            if (textBox_Insertar.Text != "")
            {
                Cola.Enqueue(textBox_Insertar.Text);
                dsDatos.Tables["cola"].Rows.Add(Cola.Last().ToString());
                textBox_Insertar.Text = "";
                MessageBox.Show("Agregado");

                    }
                    else
                    {
                        MessageBox.Show("Inserte el elemento cola");
                    }
        }

        private void button_borrar_Click(object sender, EventArgs e)
        {
            try
            {
                //if (Cola.Count != 0)
              //  {
                    this.BindingContext[dsDatos, "cola"].
                    RemoveAt(this.BindingContext[dsDatos, ""].Position);
                    dsDatos.WriteXml("Datos.xml");


                    MessageBox.Show("Elimino un elemento de la cola");
              //  }
              //  else
               // {
                   
               // }
            }
            catch
            {
                MessageBox.Show("Inserte el elemento cola, ya que está vacia.");
            }

        }

        private void Form4_Load(object sender, EventArgs e)
        {
            
           
        }

        private void button_guardar_Click(object sender, EventArgs e)
        {
            this.BindingContext[dsDatos, "cola"].EndCurrentEdit();
            this.BindingContext[dsDatos, "cola"].AddNew();
            dsDatos.WriteXml("Datos.xml");
            dsDatos.Clear();
        }

        private void button_cargar_Click(object sender, EventArgs e)
        {
            try
            {
                XmlDataDocument dsDatos = new XmlDataDocument();
                dsDatos.DataSet.ReadXml(Application.StartupPath + "\\Datos.xml");

                dataGridView1.DataSource = dsDatos.DataSet;
                dataGridView1.DataMember = "cola";
            }
            catch
            {
            }

        }

        private void button_atras_Click(object sender, EventArgs e)
        {
            Form1 Formulario = new Form1();
            Formulario.Show();
            this.Hide();
        }
    }
}
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;
using System.Xml;
namespace Estructura
{
    public partial class Form5 : Form
    {
        DataSet dsDatos = new DataSet("Datos");
        
        private LinkedList<string> lista;
        private LinkedListNode<string> nodoLista;

        int i = 0;
        public Form5()

        {
            try
            {
                InitializeComponent();
                lista = new LinkedList<string>();
                nodoLista = new LinkedListNode<string>("");
                dsDatos.ReadXml(Application.StartupPath + "\\Datos.xml");
                dataGridView1.DataSource = dsDatos;
                dataGridView1.DataMember = "lista";
            }
            catch
            {
            }

        }

        private void Form5_Load(object sender, EventArgs e)
        {
            
        }

        private void button_agregra_Click(object sender, EventArgs e)
        {

            //creamos la fila que vamos a agregar

            if (textBox_Insertar.Text != "")
            {
                string[] row = new string[] { textBox_Insertar.Text };

                dsDatos.Tables["lista"].Rows.Add(row);
                textBox_Insertar.Text = "";
                MessageBox.Show("Agregado.");
            }
            else
            {
                MessageBox.Show("Inserte el elemento lista");
            }
        }

        private void button_borrar_Click(object sender, EventArgs e)
        {
            try
            {
                for (i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Selected == true)
                    {
                        dsDatos.Tables["lista"].Rows.RemoveAt(i);
                        MessageBox.Show("Ha sido elimidado.");

                    }

                }
            }
            catch
            {
                MessageBox.Show("No se ha eliminado.");
            }
        }

        private void button_guardar_Click(object sender, EventArgs e)
        {
            this.BindingContext[dsDatos, "lista"].EndCurrentEdit();
            this.BindingContext[dsDatos, "lista"].AddNew();
            dsDatos.WriteXml("Datos.xml");
            dsDatos.WriteXml(Application.StartupPath + "\\Datos.xml"); 
                       dsDatos.Clear();
        }

        private void button_cargar_Click(object sender, EventArgs e)
        {
            XmlDataDocument dsDatos = new XmlDataDocument();
            dsDatos.DataSet.ReadXml(Application.StartupPath + "\\Datos.xml");

            dataGridView1.DataSource = dsDatos.DataSet;
            dataGridView1.DataMember = "lista";
        }

        private void button_atras_Click(object sender, EventArgs e)
        {
            Form1 Formulario = new Form1();
            Formulario.Show();
            this.Hide();
        }
    }
}



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 Estructura
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
            webBrowser1.Navigate("http://www.google.com");
        }

           

        private void button_atras_Click(object sender, EventArgs e)
        {
            Form1 Formulario = new Form1();
            Formulario.Show();
            this.Hide();
        }


        private void Form6_Load(object sender, EventArgs e)
        {

        }
    }
}

Documento xml llamado Datos.xml ahi guardare mis etiquetas


Programa hecho en visual studio
lenguaje: c#
Descripcion:se realiza un un menu con todas las utilidades que va a tener en este caso colo ,pila y listas
se realiza un codigo donde se tendra en canta un documento xml  que actua deacuerdo a las accienes que le demos como guardar ,agregar,borrar ,cargar ....

Comentarios

Publicar un comentario

Entradas populares de este blog

Google Glass llegará al mercado en 2014

Suma y Multiplicacion de Matrices php

Como sobrevivir a mi ex