Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef struct cell *CellPtr;
- typedef struct cell {
- int contents, row, col;
- CellPtr next, down;
- } Cell;
- CellPtr revSparse(CellPtr matrix, int width) {
- CellPtr col, row = matrix, temp=matrix, curr = matrix, p = matrix;
- int new_row;
- for (row = matrix; row != NULL; row = row->down) {
- new_row = 1;
- while (temp != NULL) {
- if (row == matrix) {
- new_row = 0;
- curr = matrix;
- col = curr->next;
- temp = col->next;
- curr = col;
- matrix->next = NULL;
- }
- if (new_row == 1) {
- new_row = 0;
- col->down = row;
- }
- if (new_row == 0) {
- col = curr->next;
- temp = col->next;
- col->next = curr;
- curr = col;
- }
- if (curr == matrix) {
- curr->next = NULL;
- }
- if (p == matrix && temp->next == NULL) {
- p = temp;
- }
- }
- return p;
- }
- }
- int main() {
- Cell t1 = {6, 1, 2, NULL, NULL};
- Cell t2 = {2, 1, 5, NULL, NULL};
- Cell t3 = {8, 1, 6, NULL, NULL};
- Cell t4 = {1, 1, 7, NULL, NULL};
- Cell t5 = {44, 2, 1, NULL, NULL};
- Cell t6 = {7, 2, 2, NULL, NULL};
- Cell t7 = {7, 2, 5, NULL, NULL};
- Cell t8 = {11, 2, 6, NULL, NULL};
- CellPtr p;
- p = &t1;
- t1.next = &t2;
- t2.next = &t3;
- t3.next = &t4;
- t1.down = &t5;
- t5.next = &t6;
- t6.next = &t7;
- t7.next = &t8;
- revSparse(p, 20);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement