Guest User

Untitled

a guest
Jul 16th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class nodo1 {
  6. friend class nodo2;
  7. friend class MatrizDisp;
  8. int posicion;
  9. nodo2* columna; /* puntero a la lista que cuelga de este nodo y
  10. almacena los valores no nulos de la columna posicion */
  11. nodo1* sig1;
  12. };
  13.  
  14.  
  15. class nodo2 {
  16. friend class MatrizDisp;
  17. int elemento; /* valor en la matriz */
  18. int tono_gris;
  19. int fila;
  20. nodo2* sig2;
  21. };
  22.  
  23.  
  24. class MatrizDisp {
  25. friend class nodo1;
  26. friend class nodo2;
  27. int nfilas;
  28. int ncolumnas;
  29. nodo1* matriz;
  30.  
  31. private:
  32.  
  33. nodo2* CreaColumna(int Fila, int Elemento, int Gris, nodo2* sig) {
  34. nodo2* fil = new(nodo2);
  35. fil->fila = Fila;
  36. fil->elemento = Elemento;
  37. fil->tono_gris = Gris;
  38. fil->sig2 = sig;
  39. return fil;
  40. }
  41.  
  42.  
  43. nodo1* CreaNodo(int Fila, int Columna, int Elemento, int Gris,
  44. nodo1* sig) {
  45. nodo1* col = new(nodo1);
  46. col->posicion = Columna;
  47. col->sig1 = sig;
  48. col->columna = CreaColumna(Fila, Elemento, Gris, NULL);
  49. return col;
  50. }
  51.  
  52.  
  53. public:
  54.  
  55. MatrizDisp(int Filas, int Columnas) {
  56. nfilas = Filas;
  57. ncolumnas = Columnas;
  58. matriz = NULL;
  59. }
  60.  
  61.  
  62. void insertar(int Fila, int Columna, int Elemento, int Gris) {
  63. if (Elemento == 0) return;
  64. if (matriz == NULL) {
  65. matriz = CreaNodo(Fila, Columna, Elemento, Gris, NULL);
  66. }
  67. else {
  68. nodo1* act = matriz;
  69. nodo1* ant = NULL;
  70. while(act != NULL and act->posicion < Columna) {
  71. ant = act;
  72. act = act->sig1;
  73. }
  74. if (act!=NULL and act->posicion==Columna) {
  75. nodo2* act2 = act->columna;
  76. nodo2* ant2 = NULL;
  77. while(act2 != NULL and act2->fila < Fila) {
  78. ant2 = act2;
  79. act2 = act2->sig2;
  80. }
  81. if (act2!=NULL and act2->fila==Fila) {
  82. act2->elemento = Elemento;
  83. act2->tono_gris = Gris;
  84. }
  85. else {
  86. nodo2* nueva2 = CreaColumna(Fila, Elemento, Gris, act2);
  87. ant2->sig2 = nueva2;
  88. }
  89. }
  90. else {
  91. nodo1* nueva = CreaNodo(Fila, Columna, Elemento, Gris, act);
  92. ant->sig1 = nueva;
  93. }
  94. }
  95. }
  96.  
  97.  
  98. void suprimir(int Fila, int Columna) {
  99. if (matriz != NULL) {
  100. nodo1* act = matriz;
  101. nodo1* ant = NULL;
  102. while(act != NULL and act->posicion < Columna) {
  103. ant = act;
  104. act = act->sig1;
  105. }
  106. if (act!=NULL and act->posicion==Columna) {
  107. nodo2* act2 = act->columna;
  108. nodo2* ant2 = NULL;
  109. while(act2 != NULL and act2->fila < Fila) {
  110. ant2 = act2;
  111. act2 = act2->sig2;
  112. }
  113. if (act2!=NULL and act2->fila==Fila) {
  114. if (ant2 != NULL) ant2->sig2 = act2->sig2;
  115. else if (act2->sig2 != NULL) act->columna = act2->sig2;
  116. else {
  117. if (ant != NULL) ant->sig1 = act->sig1;
  118. else matriz = act->sig1;
  119. delete(act);
  120. }
  121. delete(act2);
  122. }
  123. }
  124. }
  125. }
  126.  
  127.  
  128. void limpiar() {
  129. if (matriz != NULL) {
  130. nodo1* act = matriz;
  131. nodo1* ant = NULL;
  132. while(act != NULL) {
  133. ant = act;
  134. act = act->sig1;
  135.  
  136. nodo2* act2 = act->columna;
  137. nodo2* ant2 = NULL;
  138. while(act2 != NULL) {
  139. if (act2->tono_gris < 20) {
  140. nodo2* auxsig2 = act2->sig2;
  141. if (ant2 != NULL) ant2->sig2 = act2->sig2;
  142. else if (act2->sig2 != NULL) act->columna = act2->sig2;
  143. else {
  144. nodo1* auxsig1 = act->sig1;
  145. if (ant != NULL) ant->sig1 = act->sig1;
  146. else matriz = act->sig1;
  147. act = auxsig1;
  148. delete(act);
  149. }
  150. act2 = auxsig2;
  151. delete(act2);
  152. }
  153. else {
  154. act2 = act2->sig2;
  155. ant2 = act2;
  156. }
  157. }
  158. }
  159. }
  160. }
  161.  
  162.  
  163. int compara(MatrizDisp M1) {
  164.  
  165. }
  166. };
Add Comment
Please, Sign In to add comment