Created
November 13, 2012 13:18
-
-
Save juanfal/4065727 to your computer and use it in GitHub Desktop.
encontrar posición de un valor en una matriz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int N = 10; | |
const int M = 100; | |
typedef int TMatriz[N][M]; | |
void Encuentrax(TMatriz m, int x, int& pi, int& pj) | |
{ | |
pi = pj = -1; | |
int j, i = 0; | |
while (i<N and m[i][j] != x) { | |
j = 0; | |
while (j<M and m[i][j] != x) { | |
++j; | |
} | |
++i; | |
} | |
if (i<N) { | |
pi = i; | |
pj = j; | |
} | |
} | |
void Encuentrax2(TMatriz m, int x, int& pi, int& pj) | |
{ | |
pi = pj = -1; | |
int i = 0, j = 0; | |
while (i < N and m[i][j] != x) { | |
++j; | |
if (j == M) { | |
j = 0; | |
++i; | |
} | |
} | |
if (i<N) { | |
pi = i; | |
pj = j; | |
} | |
} | |
void Encuentrax3(TMatriz m, int x, int& pi, int& pj) | |
{ | |
pi = pj = -1; | |
for (int i = 0; i < N; ++i) | |
for (int j = 0; j < M; ++j) | |
if (m[i][j] == x) { | |
pi = i; | |
pj = j; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment