0
typedef struct tempNo {
int valor;
int coluna;
struct tempNo* prox;
} NO;
typedef NO* PONT;
typedef struct {
PONT* A;
int linhas;
int colunas;
} MATRIZ;
void inicializaMatriz(MATRIZ* m, int linnha, int coluna) {
int i;
m->linhas = linnha;
m->colunas = coluna;
m->A = (PONT*) malloc(linnha*sizeof(PONT));
for (i = 0; i < linnha ; i++){
m->A[i] = NULL;
}
}
int atribuirValor(MATRIZ* m, int lin, int col, int valor) {
if (lin < 0 || lin >= m->linhas || col < 0 || col >= m->colunas ) return 1;
PONT ant = NULL;
PONT atual = m->A[lin];
while(atual != NULL && atual->coluna < col ){
ant = atual;
atual = atual->prox;
}
if (atual != NULL && atual->coluna == col) {
if (valor == 0) {
if (ant == NULL) m->A[lin] = atual->prox;
else ant->prox = atual->prox;
free(atual);
}
else atual->valor = valor;
} else if (valor != 0){
PONT novo = (PONT) malloc (sizeof(NO));
novo->coluna = col;
novo->valor = valor;
novo->prox = atual;
if (ant == NULL) m->A[lin] = novo;
else ant->prox = novo;
}
return 0;
}
int acessarValor(MATRIZ* m, int lin , int col) {
if (lin < 0 || lin >= m->linhas || col < 0 || col >= m->colunas ) return 0;
PONT atual = m->A[lin];
while (atual != NULL && atual->coluna < col )
atual = atual->prox;
if (atual != NULL && atual->coluna == col)
return atual->valor;
return 0;
}
void anxexarColuna(MATRIZ* m){
int i = m->colunas;
i = i + 1;
m->colunas = i;
}
void anexarLinha(MATRIZ* m){
int i = m->linhas;
i = i + 1;
}
What structure are you trying to relocate and where in the code exactly ? When you expose your problem try to be as specific as possible.
– Isac
PONT* A : It is a pointer list for NO that points to the beginning of each list of NO. PONT* A, represents the columns of my Matrix. Already NO are linked lists with pointers to Prox that represent the lines of my Matrix. I want to allocate more space for PONT* A. because as seen in the Attach columns function to add more columns I need to do this, allocate more space in PONT* A.
– Selton Farias
In what function ? reallocate to an array is done with realloc
– Isac
In the column attach function. I tried to use realloc but was unsuccessful.
– Selton Farias