Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pila
- {
- private int max;
- private int top;
- private int[] arreglo;
- public Pila(int t)
- {
- this.max = t;
- this.top = 0;
- this.arreglo = new int[t];
- }
- private bool EstaVacia()
- {
- return this.top == 0;
- }
- private bool EstaLleno()
- {
- return this.top == this.max;
- }
- public bool Push(int dato)
- {
- if (!EstaLleno())
- {
- this.arreglo[this.top] = dato;
- this.top++;
- return (true);
- } else
- return (false);
- }
- public bool Pop(bool verbose)
- {
- if (!EstaVacia()) {
- this.top--;
- return (true);
- } else
- return (false);
- }
- public string Mostrar()
- {
- /*
- * 3?|?*789?|
- * 2?|?4321?|
- * 1?|?**21?|
- * 0?|?***7?|
- */
- string salida = "";
- for (int i = this.max-1; i >= 0; i--)
- {
- salida += i + " | ";
- }
- //string salida = "";
- //int maxcar = 0;
- //int cmax = max.ToString().Length;
- //String[] car = new string[max];
- //#region Contador caracteres
- //for (int j = this.max - 1; j > -1; j--)
- //{
- // string pos = arreglo[j].ToString();
- // if (pos.Length > maxcar)
- // {
- // maxcar = pos.Length;
- // }
- //}
- //#endregion
- //#region Caracterizador
- //for (int k = max - 1; k > -1; k--)
- //{
- // string pos = arreglo[k].ToString();
- // int carr = pos.Length;
- // for (int l = carr; l <= maxcar; l++)
- // {
- // car[k] += " ";
- // }
- //}
- //#endregion
- //for (int i = max - 1; i > -1; i--)
- //{
- // string sp = "";
- // string pos = i.ToString();
- // int pos1 = pos.Length;
- // while (pos1 != cmax)
- // {
- // sp += " ";
- // pos1++;
- // }
- // if (i < top)
- // {
- // salida += i + "| " + sp + "[" + car[i] + arreglo[i] + "]";
- // }
- // else
- // {
- // car[i] += " ";
- // salida += i + "| " + sp + "[" + car[i] + "]";
- // }
- // if (i == top)
- // {
- // salida += " t";
- // }
- // if (i != top && arreglo[i] != 0)
- // {
- // salida += " c";
- // }
- // salida += "\n";
- //}
- return salida;
- }
- public void Vaciar()
- {
- this.top = 0;
- }
- }//fin pila
- }//fin namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement