Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. typedef struct cell *CellPtr;
  4. typedef struct cell {
  5. int contents, row, col;
  6. CellPtr next, down;
  7. } Cell;
  8.  
  9. CellPtr revSparse(CellPtr matrix, int width) {
  10. CellPtr col, row = matrix, temp=matrix, curr = matrix, p = matrix;
  11. int new_row;
  12. for (row = matrix; row != NULL; row = row->down) {
  13. new_row = 1;
  14. while (temp != NULL) {
  15. if (row == matrix) {
  16. new_row = 0;
  17. curr = matrix;
  18. col = curr->next;
  19. temp = col->next;
  20. curr = col;
  21. matrix->next = NULL;
  22. }
  23. if (new_row == 1) {
  24. new_row = 0;
  25. col->down = row;
  26. }
  27. if (new_row == 0) {
  28. col = curr->next;
  29. temp = col->next;
  30. col->next = curr;
  31. curr = col;
  32. }
  33. if (curr == matrix) {
  34. curr->next = NULL;
  35. }
  36. if (p == matrix && temp->next == NULL) {
  37. p = temp;
  38. }
  39. }
  40. return p;
  41. }
  42. }
  43.  
  44. int main() {
  45. Cell t1 = {6, 1, 2, NULL, NULL};
  46. Cell t2 = {2, 1, 5, NULL, NULL};
  47. Cell t3 = {8, 1, 6, NULL, NULL};
  48. Cell t4 = {1, 1, 7, NULL, NULL};
  49. Cell t5 = {44, 2, 1, NULL, NULL};
  50. Cell t6 = {7, 2, 2, NULL, NULL};
  51. Cell t7 = {7, 2, 5, NULL, NULL};
  52. Cell t8 = {11, 2, 6, NULL, NULL};
  53.  
  54. CellPtr p;
  55. p = &t1;
  56. t1.next = &t2;
  57. t2.next = &t3;
  58. t3.next = &t4;
  59. t1.down = &t5;
  60. t5.next = &t6;
  61. t6.next = &t7;
  62. t7.next = &t8;
  63.  
  64.  
  65. revSparse(p, 20);
  66.  
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement