Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. #region Campos
  2. int max;
  3. int top;
  4. int[] arreglo;
  5. #endregion
  6.  
  7.  
  8. #region Constructor
  9. /// <summary>
  10. /// Metodo constructor de la clase
  11. /// </summary>
  12. /// <param name="m">Indica el tamaño del arreglo</param>
  13. public ClaseArregloDesordenado(int m)
  14. {
  15. this.arreglo = new int[m];
  16. this.top = 0;
  17. this.max = m;
  18.  
  19. }
  20. #endregion
  21. public void PrecargarCompleta()
  22. {
  23. this.arreglo = new int[] { 7, 3, 9, 4, 6, 5 };
  24. this.max = this.arreglo.Length;//6
  25. this.top= this.arreglo.Length;
  26.  
  27. }
  28.  
  29. /// <summary>
  30. /// Metodo que determina si el arreglo esta lleno,valida al metodo Eliminar e Insertar
  31. /// </summary>
  32. /// <returns>True si esta lleno, False si no lo esta</returns>
  33. public bool EstaLleno()
  34. {
  35. if (this.top == this.max)
  36. {
  37. return true;
  38. }
  39. return false;
  40. }
  41. /// <summary>
  42. /// Metodo que determina si el arreglo esta vacio , para validar al metodo Eliminar e Insertar
  43. /// </summary>
  44. /// <returns>True si esta vacio y False si no lo esta</returns>
  45. public bool EstaVacio()
  46. {
  47. if(this.top==0)
  48. return true;
  49.  
  50. return false;
  51. }
  52. /// <summary>
  53. /// Metodo que vacia el arreglo
  54. /// </summary>
  55. public void Vaciar()
  56. {
  57. this.top = 0;
  58.  
  59. }
  60. /// <summary>
  61. /// Metodo que inserta un valor en el arreglo
  62. /// </summary>
  63. /// <param name="dato">Valor a arreglar en el arreglo</param>
  64. /// <returns></returns>
  65. public bool Insertar(int dato)
  66. {
  67. if (!EstaLleno())
  68. {
  69. for (int i = 0; i < this.top; i++)
  70. {
  71. if (this.arreglo[i]==dato)
  72. return false;
  73. }
  74. this.arreglo[this.top] = dato;
  75. this.top++;
  76. return true;
  77. }//fin del critico
  78. return false;
  79.  
  80. }
  81. /// <summary>
  82. /// Metodo que elimina un elemento del arreglo,validado por el metodo EstaVacio
  83. /// </summary>
  84. /// <param name="dato">dato a eliminar</param>
  85. /// <returns>True si pudo eliminar el dato</returns>
  86. public bool Eliminar(int dato)
  87. {
  88. if (!EstaVacio())
  89. {
  90. for (int i = 0; i < this.top; i++)
  91. {
  92. if (this.arreglo[i]==dato)
  93. {
  94. for (int j = i; j < this.top-1; j++)
  95. {
  96. this.arreglo[j] = this.arreglo[j + 1];
  97. this.top--;
  98. return true;
  99. }
  100. }
  101. }
  102. return false;
  103. }//fin del critico
  104. return false;
  105. }
  106. /// <summary>
  107. /// Metodo que regresa una cadena de caracteres que representa el contenido del arreglo
  108. /// </summary>
  109. /// <returns>Cadena con el contenido del arreglo</returns>
  110. public string Mostrar()
  111. {
  112. string salida = "{";
  113. for (int i = 0; i < this.top; i++)
  114. {
  115. salida += this.arreglo[i];
  116. if (i<this.top-1)
  117. {
  118. salida += ",";
  119. }
  120. }
  121. salida += "}";
  122. return salida;
  123. }
  124. /// <summary>
  125. /// Metodo que regresa el indice de un valor dentro del arreglo
  126. /// </summary>
  127. /// <param name="dato">valor entero a buscar en el arreglo</param>
  128. /// <returns>numero entero mayor o igual a 0 para indicar la posicion(inidice) del valor buscado;-1 en caso de queel valor no exista en el arreglo</returns>
  129. public int BuscarValorArreglo(int dato)
  130. {
  131. for (int i = 0; i < this.top; i++)
  132. {
  133. if (this.arreglo[i] == dato)
  134. {
  135. return i;
  136. }
  137. }
  138. return -1;
  139. }
  140. /// <summary>
  141. /// Metodo que ordena el contenido del arreglo
  142. /// </summary>
  143. /// <returns>True si el arreglo se ordeno y False si no se ordeno</returns>
  144. public bool Ordenar()
  145. {
  146. return true;
  147. }
  148. /// <summary>
  149. /// Metodo que regresa el valor mas grande almacenado en el arreglo
  150. /// </summary>
  151. /// <returns>Valor mayor dentro del arreglo</returns>
  152. public int ObtenerMayor()
  153. {
  154. int mayor = int.MinValue;
  155. for (int i = 0; i < this.top; i++)
  156. {
  157. if (this.arreglo[i]>mayor)
  158. {
  159. mayor = this.arreglo[i];
  160. }
  161. }
  162. return mayor;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement