Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. class Pila
  2. {
  3. private int max;
  4. private int top;
  5. private int[] arreglo;
  6.  
  7. public Pila(int t)
  8. {
  9. this.max = t;
  10. this.top = 0;
  11. this.arreglo = new int[t];
  12. }
  13.  
  14. private bool EstaVacia()
  15. {
  16.  
  17. return this.top == 0;
  18. }
  19.  
  20. private bool EstaLleno()
  21. {
  22. return this.top == this.max;
  23. }
  24.  
  25. public bool Push(int dato)
  26. {
  27. if (!EstaLleno())
  28. {
  29. this.arreglo[this.top] = dato;
  30. this.top++;
  31. return (true);
  32. } else
  33. return (false);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. public bool Pop(bool verbose)
  40. {
  41. if (!EstaVacia()) {
  42. this.top--;
  43. return (true);
  44. } else
  45. return (false);
  46. }
  47.  
  48.  
  49. public string Mostrar()
  50. {
  51. /*
  52. * 3?|?*789?|
  53. * 2?|?4321?|
  54. * 1?|?**21?|
  55. * 0?|?***7?|
  56. */
  57.  
  58. string salida = "";
  59.  
  60. for (int i = this.max-1; i >= 0; i--)
  61. {
  62. salida += i + " | ";
  63.  
  64. }
  65. //string salida = "";
  66. //int maxcar = 0;
  67. //int cmax = max.ToString().Length;
  68. //String[] car = new string[max];
  69.  
  70. //#region Contador caracteres
  71. //for (int j = this.max - 1; j > -1; j--)
  72. //{
  73.  
  74. // string pos = arreglo[j].ToString();
  75. // if (pos.Length > maxcar)
  76. // {
  77. // maxcar = pos.Length;
  78. // }
  79. //}
  80. //#endregion
  81.  
  82. //#region Caracterizador
  83. //for (int k = max - 1; k > -1; k--)
  84. //{
  85. // string pos = arreglo[k].ToString();
  86. // int carr = pos.Length;
  87. // for (int l = carr; l <= maxcar; l++)
  88. // {
  89. // car[k] += " ";
  90. // }
  91. //}
  92. //#endregion
  93.  
  94. //for (int i = max - 1; i > -1; i--)
  95. //{
  96.  
  97. // string sp = "";
  98. // string pos = i.ToString();
  99. // int pos1 = pos.Length;
  100. // while (pos1 != cmax)
  101. // {
  102. // sp += " ";
  103. // pos1++;
  104. // }
  105.  
  106.  
  107.  
  108. // if (i < top)
  109. // {
  110. // salida += i + "| " + sp + "[" + car[i] + arreglo[i] + "]";
  111. // }
  112. // else
  113. // {
  114. // car[i] += " ";
  115. // salida += i + "| " + sp + "[" + car[i] + "]";
  116. // }
  117.  
  118. // if (i == top)
  119. // {
  120. // salida += " t";
  121. // }
  122.  
  123. // if (i != top && arreglo[i] != 0)
  124. // {
  125. // salida += " c";
  126. // }
  127.  
  128. // salida += "\n";
  129.  
  130. //}
  131.  
  132. return salida;
  133. }
  134.  
  135. public void Vaciar()
  136. {
  137. this.top = 0;
  138. }
  139. }//fin pila
  140. }//fin namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement