I want to pass liked list to function and create new list. I need some help to understand what I'm doing wrong. I create new pointer and copy the pointer to "curr" and than run on the list and built in. I try to find in which step I got it wrong . I already try to debug the program.
the struct is simple struct If i, j and the value of the matrix A are an arithmetic series they are added to the list.
int createList(int A[][COLS], list** lst, int rows, int cols)
{
// your code:
*lst = (list*)calloc(1, sizeof(list));
list* curr = *lst;
int i, j;
int counter = 0;
int d;
int check = 0;
int j_i;
int A_j;
four new_four;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
j_i = j - i;
A_j = A[i][j] - j;
if (j_i == A_j) {
d = j-i;
new_four = createFour(i, j, d, A[i][j]);
if (counter == 0) {
curr = createElement(new_four);
}
counter++;
curr->next = createElement(new_four);
curr = curr->next;
}
}
}
curr->next = NULL;
return counter;
}
// create new object with all the parameters
four createFour(int i, int j, int d, int value)
{
four new_f;;
new_f.d = d;
new_f.i = i;
new_f.j = j;
new_f.value = value;
return new_f;
}
// create new Element with the data to the list
list* createElement(four data)
{
// your code:
list* new_Element = (list*)calloc(1, sizeof(list));
new_Element->data = data;
new_Element->next = (list*)calloc(1, sizeof(list));
return new_Element;
}
list,createFour,four,createElementetc. are.