mirror of
				https://gitlab.com/klmp200/LO27.git
				synced 2025-10-31 08:23:04 +00:00 
			
		
		
		
	SequenceOnMatrix operations
This commit is contained in:
		| @@ -51,7 +51,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ | ||||
|  | ||||
| 	Row = GetElementPos(matrix.rows,RowPos); | ||||
| 	if (Row != NULL && Row->data != NULL){ | ||||
| 		 | ||||
|  | ||||
| 		if (Row->data->colIndex == ColPos){ | ||||
| 			error ++; | ||||
| 		} else if (Row->data->colIndex > ColPos){ | ||||
| @@ -77,7 +77,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ | ||||
|  | ||||
| 	Col = GetElementPos(matrix.cols,ColPos); | ||||
| 	if (Col != NULL && Col->data != NULL){ | ||||
| 		 | ||||
|  | ||||
| 		if (Col->data->rowIndex == RowPos){ | ||||
| 			error ++; | ||||
| 		} else if (Col->data->rowIndex > RowPos){ | ||||
| @@ -134,7 +134,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ | ||||
|  | ||||
| 	ListElement * Row = NULL; | ||||
| 	ListElement * Col = NULL; | ||||
| 	 | ||||
|  | ||||
| 	elem = FindMatrixElem(matrix,ColPos,RowPos); | ||||
| 	if (elem == NULL){ | ||||
| 		return 0; | ||||
| @@ -161,7 +161,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ | ||||
| 		} else { | ||||
| 			tmp->nextCol = elem->nextCol; | ||||
| 		} | ||||
| 		 | ||||
|  | ||||
| 	} | ||||
| 	if (Row->data == NULL){ | ||||
| 		RemoveElementPos(matrix.rows,RowPos); | ||||
| @@ -187,12 +187,12 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ | ||||
| 			return -4; /* should never happend */ | ||||
| 		} else { | ||||
| 			tmp->nextRow = elem->nextRow; | ||||
| 		}	 | ||||
| 		} | ||||
| 	} | ||||
| 		if (Col->data == NULL){ | ||||
| 		RemoveElementPos(matrix.cols,ColPos); | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	FreeCellElement(elem); | ||||
| 	return 1; | ||||
|  | ||||
| @@ -225,16 +225,18 @@ void BasicPrintMatrix(Matrix matrix){ | ||||
| /* Non optimisé : debug fx */ | ||||
| 	int i = 0; | ||||
| 	int j = 0; | ||||
| 	bool b; | ||||
|  | ||||
| 	printf("\n---PRINT MATRIX---\n"); | ||||
|  | ||||
| 	for (i=0;i<matrix.colCount;i++){ | ||||
| 	for (i=0;i<matrix.rowCount;i++){ | ||||
| 		printf("| "); | ||||
| 		for (j=0;j<matrix.rowCount;j++){ | ||||
| 	 | ||||
| 			if (GetCellValue(matrix,i,j) == true){ | ||||
| 		for (j=0;j<matrix.colCount;j++){ | ||||
|  | ||||
| 			b = GetCellValue(matrix,j,i); | ||||
| 			if (b == true){ | ||||
| 				printf("1 "); | ||||
| 			}else if (GetCellValue(matrix,i,j) == false){ | ||||
| 			}else if (b == false){ | ||||
| 				printf("0 "); | ||||
| 			}else{ | ||||
| 				printf("X "); /* error out of bounds, should never happend*/ | ||||
| @@ -244,14 +246,14 @@ void BasicPrintMatrix(Matrix matrix){ | ||||
| 		printf("|\n"); | ||||
|  | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	printf("---END OF MATRIX---\n\n"); | ||||
| } | ||||
|  | ||||
| bool RecursiveFreeCol(Matrix matrix, cellElement * elem){ | ||||
| 	cellElement * tmp = NULL; | ||||
| 	ListElement * Row = NULL; | ||||
| 	 | ||||
|  | ||||
| 	if (elem == NULL){ | ||||
| 		return ERROR; | ||||
| 	} | ||||
| @@ -259,11 +261,11 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem){ | ||||
| 	if (elem->nextRow != NULL){ | ||||
| 		RecursiveFreeCol(matrix,elem->nextRow); | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	if (elem->nextRow == NULL){ | ||||
| 	 | ||||
|  | ||||
| 		Row = GetElementPos(matrix.rows,elem->rowIndex); | ||||
| 	 | ||||
|  | ||||
| 		if (Row == NULL || Row->data == NULL ){ | ||||
| 			return ERROR; /*should never happend*/ | ||||
| 		} | ||||
| @@ -280,7 +282,7 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem){ | ||||
| 			} else { | ||||
| 				tmp->nextCol = elem->nextCol; | ||||
| 			} | ||||
| 			 | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		FreeCellElement(elem); | ||||
| @@ -311,6 +313,75 @@ Matrix freeMatrix(Matrix matrix){ | ||||
| } | ||||
|  | ||||
|  | ||||
| Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){ | ||||
| 	bool a; | ||||
| 	bool b; | ||||
| 	int i; | ||||
| 	int j; | ||||
| 	Matrix newM = CreateMatrix(); | ||||
|  | ||||
|  | ||||
| 	newM.rowCount = m.rowCount; | ||||
| 	if (m.colCount <= 1){ | ||||
| 		newM.colCount = 0; | ||||
| 		return newM; | ||||
| 	} | ||||
| 	newM.colCount = m.colCount - 1; | ||||
|  | ||||
| 	for (i=0;i < m.colCount - 1;i++){ | ||||
| 		for (j=0;j < m.rowCount;j++){ | ||||
| 			a = GetCellValue(m, i, j); | ||||
| 			b = GetCellValue(m, i + 1, j); | ||||
| 			if (operator(a, b)){ | ||||
| 				SetCellValue(newM, i, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return newM; | ||||
| } | ||||
|  | ||||
| Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){ | ||||
| 	bool a; | ||||
| 	bool b; | ||||
| 	int i; | ||||
| 	int j; | ||||
| 	Matrix newM = CreateMatrix(); | ||||
|  | ||||
| 	newM.colCount = m.colCount; | ||||
| 	if (m.rowCount <= 1){ | ||||
| 		newM.rowCount = 0; | ||||
| 		return newM; | ||||
| 	} | ||||
| 	newM.rowCount = m.rowCount - 1; | ||||
|  | ||||
| 	for (i=0; i < m.colCount;i++){ | ||||
| 		for (j=0;j < m.rowCount - 1;j++){ | ||||
| 			a = GetCellValue(m, i, j); | ||||
| 			b = GetCellValue(m, i, j + 1); | ||||
| 			if (operator(a, b)){ | ||||
| 				SetCellValue(newM, i, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return newM; | ||||
| } | ||||
|  | ||||
| Matrix andColSequenceOnMatrix(Matrix m){ | ||||
| 	return colSequenceOnMatrix(m, AND); | ||||
| } | ||||
|  | ||||
| Matrix orColSequenceOnMatrix(Matrix m){ | ||||
| 	return colSequenceOnMatrix(m, OR); | ||||
| } | ||||
|  | ||||
| Matrix andRowSequenceOnMatrix(Matrix m){ | ||||
| 	return rowSequenceOnMatrix(m, AND); | ||||
| } | ||||
|  | ||||
| Matrix orRowSequenceOnMatrix(Matrix m){ | ||||
| 	return rowSequenceOnMatrix(m, OR); | ||||
| } | ||||
|  | ||||
| /* todos : | ||||
| *finir le freeMatrix | ||||
| *chasser les bugs | ||||
|   | ||||
| @@ -120,7 +120,7 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows); | ||||
| /** | ||||
| *Basically print the Matrix in the standard output | ||||
| * | ||||
| *@param matrix the Matrix  | ||||
| *@param matrix the Matrix | ||||
| * | ||||
| *@return void | ||||
| * | ||||
| @@ -131,6 +131,61 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem); | ||||
|  | ||||
| Matrix freeMatrix(Matrix matrix); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M rows and N-1 columns were each element corresponds to the operator boolean operation | ||||
| *  between two successive horizontal elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @param operator a function | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M-1 rows and N columns were each element corresponds to the operator boolean operation | ||||
| *  between two succesive vertical elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @param operator a function | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M rows and N-1 columns were each element corresponds to the AND boolean operation | ||||
| *  between two successive horizontal elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix andColSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M rows and N-1 columns were each element corresponds to the OR boolean operation | ||||
| *  between two successive horizontal elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix orColSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M-1 rows and N columns were each element corresponds to the AND boolean operation | ||||
| *  between two succesive vertical elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix andRowSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Given an input matrix with M rows and N columns, computes a matrix with | ||||
| *  M-1 rows and N columns were each element corresponds to the OR boolean operation | ||||
| *  between two succesive vertical elements in the input matrix | ||||
| * @param m a Matrix | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix orRowSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| #endif | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user