행렬의 0이 아닌 요소에 대한 입력 스트림을 Compressed Sparse Representation으로 표현하는 프로그램을 작성하려고합니다. 함수 csr은 main 함수에서 새로운 0이 아닌 숫자가 발견 될 때마다 호출됩니다. printf 문은 함수를 호출 할 때마다 다른 값을 제공합니다. 목록 은 목록이 비어있는 첫 번째 if 문을 제외하고는 어디에도 업데이트되지 않습니다. 'a'및 v
은 re_ar
유형의 두 개의 링크 된 목록입니다. 0, N-1이 함수를 호출 할 때 헤드 노드가 계속 변경되는 이유를 모르겠습니다.
struct re_ar{
float x;
struct re_ar *nxt;
}; //structure for each node of a list containing real numbers
typedef struct re_ar re_ar;
struct in_ar{
re_ar *a;
re_ar *v;
}; //structure for each node of an array containing pointers to two lists of type re_ar
typedef struct in_ar in_ar;
in_ar *ia; //ia is an array
re_ar *a_h=NULL;re_ar *a_t=NULL;
re_ar *v_h=NULL;re_ar *v_t=NULL; //a_h, v_h are head nodes for lists a & v
int n; //a_t, v_t are tail nodes
void csr(float d, int r_i, int c_i) //r_i-row number, c_i-column number, d- entry
{
re_ar a_n;
re_ar v_n; //a_n v_n are new nodes
a_n.nxt = NULL;
v_n.nxt = NULL;
a_n.x = d;
v_n.x = c_i; //assigning data to both nodes
if(a_h == NULL) //Checking if the list is empty
{
a_h = &a_n;
v_h = &v_n;
a_t = &a_n;
v_t = &v_n; //Connecting head and tail nodes to the first node
(ia[r_i].a) = &a_n;
(ia[r_i].v) = &v_n; //Pointing ia[r_i] to the first node of both the lists
}
else //For non-empty cases
{
a_t->nxt=&a_n;
a_t=&a_n;
v_t->nxt=&v_n;
v_t=&v_n; //Adding nodes to the list
if(ia[r_i].a==NULL) //Checking if ia[r_i] has been already pointed to a node
{
ia[r_i].a=&a_n;
ia[r_i].v=&v_n; //Connecting ia[r_i] to the current node
}
}
printf("%f", v_h->x);
}
변수의 이름이 잘못되었습니다. – mikek3332002
우리는're_ar' 또는'ia'가 무엇인지 모릅니다 - 아마도'typedef struct's 일 겁니다. 변수 명명은 좋지 않습니다. –
이것은 바보입니다. 다른 사람들이 당신의 코드를 읽을 것이라고 기대한다면, 당신은 그것을 읽기 쉽게 만들어야합니다. 변수 이름을 바꾸고 질문을 수정하십시오. – ooga