typedefstruct Elem {
int x;
unsignedchar value;
struct Elem *next;
} Elem;
typedefstruct Row {
int y;
Elem *elems;
struct Row *next;
} Row;
Row *dense_to_sparse(unsignedchar *dense_matrix, int width, int height) {
int iarray[height][width];
int icounter = 0;
for (int i = 0; i < height; i++){
for (int j = 0; j < width; j++){
iarray[i][j] = image[icounter];
icounter++;}}
/* So dense_matrix is a 1d array. it's too abstract for me. So for my own convenient i convert it to a 2d array. Easier for using for loop anyways. so for now iarray is something as simple as this:
(0,0) = 1
(0,1) = 245
I'm going to hard code the link list before I am able to do anything. */
char* temp_pointer = null; // create a temp pointer
Elem *elem = (Elem *) malloc(sizeof(Elem)); // allocate space
elem.next = temp_pointer; // elem.next = null
elem.x = 0; elem.value = 1; // set value (0,0) = 1;
temp_pointer = elem; // linking the nodes
Elem *elem = (Elem *) malloc(sizeof(Elem)); // again allocating space for next node
elem.next = temp_pointer;
elem.x = 1; elem.value = (0,1) = 245; // set value.
temp_pointer = elem;
}
I am just trying to link 2 nodes together. I don't know if i'm doing it right or not, I don't even have the way to test it. S=. Also I learn that whenever i malloc something I need to free it. I didn't do it here.