Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _02_Arreglos_Practica_ClaseArregloV1
- {
- class ClaseArregloV1
- {
- #region Campos
- private int[] arreglo;
- private int max;
- private int top;
- #endregion
- #region Metodos
- /// <summary>
- /// Constructor de la clase
- /// </summary>
- /// <param name="m"></param>
- public ClaseArregloV1(int m)
- {
- this.arreglo = new int[m];
- this.max = m;
- this.top = 0;
- }
- public int Buscar(int dato)
- {
- //ToDo
- return 0;
- }
- public bool Eliminar(int dato)
- {
- if (!(EstaVacio()))
- {
- for (int i = 0; i < this.top; i++)
- {
- if (this.arreglo[i] == dato)
- {// fijamos el valor de i
- for (int y = i; y < this.top - 1; y++)
- this.arreglo[y] = this.arreglo[y + 1];
- this.top--;
- return true;
- }
- }
- return false;
- }
- return false;
- }
- public bool EstaLleno()
- {
- if (this.top == this.max)
- return true;
- return false;
- }
- public bool EstaVacio()
- {
- if (this.top == 0)
- return true;
- return false;
- }
- public bool Insertar(int dato) // Método para insertar un dato en el arreglo desordenado
- {
- if (!EstaLleno()) // Si no está lleno ...
- {
- for (int i = 0; i <= top - 1; i++)
- if (arreglo[i] == dato) // Comparación para detectar si el dato ya existe
- return (false); // No se insertó el dato (duplicado)
- arreglo[top] = dato; // Se inserta el dato en el arreglo
- top++; // Se incrementa la cantidad de datos del arreglo
- return (true); // Dato insertado con exito
- }
- else
- return (false); // No se insertó el dato (arreglo lleno)
- }
- public string Mostrar()
- {
- string salida = "";
- if (!(EstaVacio()))
- {
- string contenido = "Contenido: { ";
- string posicion = "Posición: [ ";
- string indice = "Indice: [ ";
- for (int i = 0; i < arreglo.Length; i++)
- {
- contenido += arreglo[i];
- posicion += new string(' ', arreglo[i].ToString().Length - i.ToString().Length) + i;
- //Indice
- if (i == top)
- indice += new string(' ', arreglo[i].ToString().Length - 1) + "T";
- else
- {
- if (i < this.top)
- indice += new string(' ', arreglo[i].ToString().Length - 1) + "C";
- else
- indice += new string(' ', arreglo[i].ToString().Length);
- }
- //Comas
- if (i != arreglo.Length - 1)
- {
- contenido += ", ";
- posicion += ", ";
- indice += " ";
- }
- }//Fin For
- contenido += " }";
- posicion += ", " + this.max + "]";
- if (top == max)
- {
- indice += " T]";
- }
- else
- indice += " ]";
- salida = contenido + "\n" + posicion + "\n" + indice + "\n";
- salida += "C: Indica las celdas con contenido; T indica la posición de TOP\n";
- return salida;
- }
- else
- salida = "Arreglo Vacío";
- return salida;
- }
- public bool Ordernar()
- {
- return false;
- }
- #endregion
- public void Vaciar()
- {
- this.top = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement