denzelboy
Messages postés7Date d'inscriptionjeudi 29 mars 2007StatutMembreDernière intervention19 mai 2008
-
23 avril 2008 à 14:43
sheorogath
Messages postés2448Date d'inscriptionsamedi 21 février 2004StatutModérateurDernière intervention29 janvier 2010
-
24 avril 2008 à 15:31
Bonjour dans le cadre de mon projet de fin d'étude que je dois en java. J'ai un header (matrix_2d.h) que je souhaite convertir en java. Mais je me trouve perdu par la suite Voici mes implementations:
/*
* Allocate memory for a two-dimensional RxC matrix.
* Returns NULL on failure.
*/
matrix_2d *matrix_2d_create(int r, int c)
{
int row;
matrix_2d *m;
m = malloc(sizeof(matrix_2d));
if (m!=NULL) {
m->row = r;
m->col = c;
m->m = malloc(r*sizeof(element_type*));
if (m->m==NULL) return NULL;
for (row=0; row<r; row++) {
m->m[row] = malloc(c*sizeof(element_type));
if (m->m[row]==NULL) return NULL;
}
}
return m;
}
/*
* Destroy a matrix.
*/
void matrix_2d_destroy(matrix_2d *m)
{
int row;
for (row=0; row<m->row; row++) {
free(m->m[row]);
}
free(m);
}
/*
* Set all matrix elements to zero.
*/
void matrix_2d_clear(matrix_2d *m)
{
int row, col;
for (row=0; row<m->row; row++) {
for (col=0; col<m->col; col++) {
m->m[row][col] = 0;
}
}
}
/*
* Display a matrix.
*/
void matrix_2d_write(matrix_2d *m)
{
int row, col;
for (row=0; row<m->row; row++) {
for (col=0; col<m->col; col++) {
printf("%3d",m->m[row][col]);
}
printf("\n");
}
}
/*
* Returns max(abs(matrix)), the absolute maximum value of a matrix.
*/
element_type matrix_2d_abs_max(matrix_2d *m)
{
int row, col;
element_type max = 0;
for (row=0; row<m->row; row++) {
for (col=0; col<m->col; col++) {
if (abs(m->m[row][col])>max) max = abs(m->m[row][col]);
}
}
public class Matrix2D {
public static final int MIN_ELEMENT_TYPE = -32768;
public static final int MAX_ELEMENT_TYPE = 32767;
private int row = 0;
private int column = 0;
private int[][] m = null;
public Matrix2D(final int r, final int c) {
if (r < 0)
throw new IllegalArgumentException("Invalid row size");
if (c < 0)
throw new IllegalArgumentException("Invalid column size"); this.m new int[(this.row r)][(this.column = c)];
}
/*
* Set all matrix elements to zero.
*/
public void clear() {
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j)
m[i][j] = 0;
}
/*
* Display a matrix.
*/
public void write() {
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j)
out.printf("%3d", m[i][j]);
out.println();
}
}
/*
* Returns max(abs(matrix)), the absolute maximum value of a matrix.
*/
public int abs_max() {
int max = 0;
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j)
if (abs(m[i][j]) > max)
max = abs(m[i][j]);
return max;
}
}
------------------------------------
"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."