帮助我实施 [英] help me with this implementation
本文介绍了帮助我实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我修复了下一个代码
I fixed the next code
<pre lang="cs">#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include <malloc.h><br />
<br />
typedef struct _nodolista{<br />
int columnindex;<br />
struct _nodolista*next;<br />
int value;<br />
}nodol;<br />
typedef struct _nodocabecera{<br />
int rowindex;<br />
nodol * next;<br />
struct _nodocabecera*down;<br />
}nodoc;<br />
typedef struct _matrix{<br />
nodoc*idlist;/* id list*/<br />
nodol*valuelist;/*value row list*/<br />
}matrix;<br />
/*this function initializes the IDlist*/<br />
nodoc * iniID(int m){<br />
nodoc* IDlist;<br />
int i;<br />
IDlist=( nodoc*)malloc(m*sizeof( nodoc));<br />
<br />
/*now we create the list of identifiers*/<br />
for (i=1;i<=m;i++){<br />
if (i==m){<br />
IDlist->rowindex=m;<br />
IDlist->next=NULL;<br />
IDlist->down=NULL;<br />
return IDlist;<br />
}<br />
IDlist->rowindex=i;<br />
IDlist->next=NULL;<br />
IDlist=IDlist->down;<br />
}<br />
return IDlist;<br />
}<br />
matrix * iniM(int m , int n){<br />
matrix * x;<br />
int i=1;<br />
/*we create the disperse matrix*/<br />
x=(matrix *)malloc(m*n*sizeof(matrix));<br />
/*we create the idlist*/<br />
x->idlist=iniID(m);<br />
/*we create the value list*/<br />
nodol* valuelist;<br />
nodoc * aux;<br />
x->valuelist=NULL;<br />
for(aux=x->idlist;aux->down!=NULL;aux=aux->down){<br />
valuelist=(nodol*)malloc(sizeof(nodol));<br />
aux->next=valuelist;<br />
valuelist->columnindex=i;<br />
for (i=2;i<=n;i++){<br />
if (i==n){<br />
valuelist=(nodol*)malloc(sizeof(nodol));<br />
valuelist->columnindex=n;<br />
valuelist->value=0;<br />
valuelist->next=NULL;<br />
return x ;<br />
}<br />
valuelist=(nodol*)malloc(sizeof(nodol));<br />
valuelist->columnindex=i;<br />
valuelist->value=0;<br />
valuelist=valuelist->next;<br />
} return x;<br />
}<br />
return x;<br />
}<br />
<br />
<br />
int dpmatrix(matrix *x){<br />
int i,j,val;<br />
nodoc * aux;<br />
nodol * aux2;<br />
<br />
for (aux=x->idlist;aux->down!=NULL;aux=aux->down){<br />
i=aux->rowindex;<br />
aux->next=x->valuelist;<br />
<br />
for (aux2=aux->next;aux2->next!=NULL;aux2=aux2->next){<br />
j=aux2->columnindex;<br />
printf("%d,%d introduzca elemento",i,j);<br />
scanf("%d",&val);<br />
if (val!=0 )<br />
aux2->value=val;<br />
}<br />
}<br />
return 0;<br />
}<br />
<br />
<br />
int main(){<br />
int i,j;<br />
matrix * M;<br />
printf("introduzca el numero de filas \n");<br />
scanf("%d",&i);<br />
printf("introduzca el numero de columnas \n");<br />
scanf("%d",&j);<br />
M=iniM(i,j);<br />
dpmatrix(M);<br />
return 0;<br />
}</pre><br />
,但它仍未编译,当我运行该程序时,它需要读取行和列的数量,然后程序挂起,如果出现内存分配问题,我就不会挂起,因为'代码没有显示任何错误,算法的逻辑很好,请有人帮我解决这个问题! ;(预先感谢
, but it''s still not compiling yet, when i run the program, it takes the numbers of rows and columns, then the program hangs, and i don''t if it''s a problem of assignment of memory, cuz'' the code doesn''t show any errors and the logic of the algorithm is well, please somebody help me with this problem ! ;( thanks in advance
推荐答案
可能有几处错误,没有正确的格式设置,等等,我没有能力去读它-特别是因为您不要告诉使用编译器在抱怨什么,但是这可能是导致未编译的原因:
There are probably several things wrong, without proper formatting and so forth I haven''t got the energy to read it - particularly since you don''t tell use what the compiler is complaining about. However this leapt out as a possible reason for non-compilation:
void initializeMatrix(matrix** M, long m,long n) {
matrix ** h;
initializeMatrix(*h,filas,columnas);
尝试从"* h"中删除"*",以使参数与您传递的内容匹配...
Try removing the "*" from the "*h" so the parameters match what you are passing...
代码有错误,即存在很多错误(例如nodoc
既不是next
也不是value
成员).
您必须:
1.仔细阅读编译器错误消息.
2.尝试修复错误,并在遇到问题时在此处询问特定问题.
祝你好运.
:)
The code is buggy, i.e. it has a lot of errors (for instancenodoc
has not eithernext
norvalue
member).
You have to:
1. Read carefully the compiler error messages.
2. Try yourself to fix the errors, asking here specific questions whenever you''re stuck.
Good luck.
:)
这篇关于帮助我实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文