Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. namespace _02_Arreglos_Practica_ClaseArregloV1
  2. {
  3. class ClaseArregloV1
  4. {
  5. #region Campos
  6. private int[] arreglo;
  7. private int max;
  8. private int top;
  9.  
  10.  
  11. #endregion
  12.  
  13. #region Metodos
  14. /// <summary>
  15. /// Constructor de la clase
  16. /// </summary>
  17. /// <param name="m"></param>
  18. public ClaseArregloV1(int m)
  19. {
  20. this.arreglo = new int[m];
  21. this.max = m;
  22. this.top = 0;
  23. }
  24.  
  25. public int Buscar(int dato)
  26. {
  27. //ToDo
  28. return 0;
  29. }
  30.  
  31. public bool Eliminar(int dato)
  32. {
  33. if (!(EstaVacio()))
  34. {
  35. for (int i = 0; i < this.top; i++)
  36. {
  37. if (this.arreglo[i] == dato)
  38. {// fijamos el valor de i
  39. for (int y = i; y < this.top - 1; y++)
  40. this.arreglo[y] = this.arreglo[y + 1];
  41. this.top--;
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
  47. return false;
  48. }
  49.  
  50. public bool EstaLleno()
  51. {
  52. if (this.top == this.max)
  53. return true;
  54. return false;
  55. }
  56.  
  57. public bool EstaVacio()
  58. {
  59. if (this.top == 0)
  60. return true;
  61. return false;
  62. }
  63.  
  64. public bool Insertar(int dato) // Método para insertar un dato en el arreglo desordenado
  65. {
  66. if (!EstaLleno()) // Si no está lleno ...
  67. {
  68. for (int i = 0; i <= top - 1; i++)
  69. if (arreglo[i] == dato) // Comparación para detectar si el dato ya existe
  70. return (false); // No se insertó el dato (duplicado)
  71. arreglo[top] = dato; // Se inserta el dato en el arreglo
  72. top++; // Se incrementa la cantidad de datos del arreglo
  73. return (true); // Dato insertado con exito
  74. }
  75. else
  76. return (false); // No se insertó el dato (arreglo lleno)
  77. }
  78.  
  79. public string Mostrar()
  80. {
  81. string salida = "";
  82. if (!(EstaVacio()))
  83. {
  84.  
  85. string contenido = "Contenido: { ";
  86. string posicion = "Posición: [ ";
  87. string indice = "Indice: [ ";
  88.  
  89. for (int i = 0; i < arreglo.Length; i++)
  90. {
  91. contenido += arreglo[i];
  92. posicion += new string(' ', arreglo[i].ToString().Length - i.ToString().Length) + i;
  93. //Indice
  94. if (i == top)
  95. indice += new string(' ', arreglo[i].ToString().Length - 1) + "T";
  96. else
  97. {
  98. if (i < this.top)
  99. indice += new string(' ', arreglo[i].ToString().Length - 1) + "C";
  100. else
  101. indice += new string(' ', arreglo[i].ToString().Length);
  102. }
  103.  
  104. //Comas
  105. if (i != arreglo.Length - 1)
  106. {
  107. contenido += ", ";
  108. posicion += ", ";
  109. indice += " ";
  110. }
  111. }//Fin For
  112.  
  113. contenido += " }";
  114. posicion += ", " + this.max + "]";
  115. if (top == max)
  116. {
  117. indice += " T]";
  118. }
  119. else
  120. indice += " ]";
  121.  
  122. salida = contenido + "\n" + posicion + "\n" + indice + "\n";
  123. salida += "C: Indica las celdas con contenido; T indica la posición de TOP\n";
  124.  
  125.  
  126. return salida;
  127. }
  128. else
  129. salida = "Arreglo Vacío";
  130. return salida;
  131. }
  132.  
  133.  
  134. public bool Ordernar()
  135. {
  136. return false;
  137. }
  138. #endregion
  139. public void Vaciar()
  140. {
  141. this.top = 0;
  142. }
  143.  
  144.  
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement