Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct cel {
- int info;
- struct cel *pn, *ps, *pw, *pe,
- *pno, *pne, *pso, *pse;
- } CEL;
- typedef struct line {
- int ncols;
- CEL *pcels;
- } LINE;
- typedef struct matrix {
- int nlines;
- LINE *plines;
- } MATRIX;
- struct resultado {
- int linha, coluna;
- resultado *next;
- };
- resultado * find_cells_with_value(MATRIX m, int valor)
- {
- resultado * RESULTADO = NULL;
- resultado * PROX_RESULTADO = RESULTADO;
- for (int lin = 0; lin < m.nlines; lin++)
- {
- LINE linha = m.plines[lin];
- for (int col = 0; col < linha.ncols; col++)
- if (linha.pcels[col].info == valor)
- {
- resultado *NOVO = (resultado*)malloc(sizeof(resultado));
- NOVO->linha = lin;
- NOVO->coluna = col;
- NOVO->next = NULL;
- if (!RESULTADO)
- RESULTADO = NOVO;
- else
- PROX_RESULTADO->next = NOVO;
- PROX_RESULTADO = NOVO;
- }
- }
- return RESULTADO;
- }
- //====================================
- void main(int argc, char* argv)
- {
- int input[] = {
- 1, 4, 7, 8, 44,
- 2, 3, 0, 9, 4,
- 9, 5, 8, 44, 12,
- 2, 4, 3, 9, 8 };
- int lins = 4;
- int cols = 5;
- MATRIX mat;
- mat.nlines = lins;
- mat.plines = (line*)malloc(lins * sizeof(line));
- for (int i = 0; i < lins; i++)
- {
- mat.plines[i].ncols = cols;
- mat.plines[i].pcels = (cel*)malloc(cols * sizeof(cel));
- for (int j = 0; j < cols; j++)
- {
- CEL *c = (cel*) malloc(sizeof(cel));
- c->info = input[i * cols + j];
- mat.plines[i].pcels[j] = *c;
- }
- }
- resultado *res = find_cells_with_value(mat, 8);
- }
Advertisement
Add Comment
Please, Sign In to add comment