1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-16 10:03:19 +00:00

Renommage des fonctions de listes

This commit is contained in:
Antoine Bartuccio 2017-01-01 16:35:34 +01:00
parent 3bcd663762
commit 28021951b4
3 changed files with 58 additions and 58 deletions

View File

@ -27,7 +27,7 @@
#define SUCCESS 0 #define SUCCESS 0
#define FAILURE 1 #define FAILURE 1
List * CreateList() { List * createList() {
List *list = malloc(sizeof(*list)); List *list = malloc(sizeof(*list));
if(list != NULL){ if(list != NULL){
@ -99,7 +99,7 @@ int push(List *list, cellElement *data){
return ok; return ok;
} }
ListElement * GetElement(List *list, int nb){ ListElement * getElement(List *list, int nb){
ListElement *current = NULL; ListElement *current = NULL;
int i; int i;
@ -129,7 +129,7 @@ ListElement * GetElement(List *list, int nb){
return current; return current;
} }
int PopPtnList(List *list, ListElement *element){ int popPtnList(List *list, ListElement *element){
int ok = SUCCESS; int ok = SUCCESS;
if (list != NULL && element != NULL){ if (list != NULL && element != NULL){
@ -158,12 +158,12 @@ int PopPtnList(List *list, ListElement *element){
return ok; return ok;
} }
int RemoveElement(List *list, int nb){ int removeElement(List *list, int nb){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *toDelete = GetElement(list, nb); ListElement *toDelete = getElement(list, nb);
if (toDelete != NULL){ if (toDelete != NULL){
ok = PopPtnList(list, toDelete); ok = popPtnList(list, toDelete);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }
@ -171,14 +171,14 @@ int RemoveElement(List *list, int nb){
} }
int shift(List *list){ int shift(List *list){
return RemoveElement(list, 0); return removeElement(list, 0);
} }
int pop(List *list){ int pop(List *list){
return RemoveElement(list, -1); return removeElement(list, -1);
} }
int DeleteListContent(List *list){ int deleteListContent(List *list){
int ok = SUCCESS; int ok = SUCCESS;
ListElement * current = NULL; ListElement * current = NULL;
ListElement * toDelete = NULL; ListElement * toDelete = NULL;
@ -205,11 +205,11 @@ int DeleteListContent(List *list){
return ok; return ok;
} }
int FreeList(List *list){ int freeList(List *list){
int ok = SUCCESS; int ok = SUCCESS;
if (list != NULL){ if (list != NULL){
ok = DeleteListContent(list); ok = deleteListContent(list);
if (ok == SUCCESS){ if (ok == SUCCESS){
free(list); free(list);
} }
@ -219,7 +219,7 @@ int FreeList(List *list){
return ok; return ok;
} }
ListElement * GetElementPos(List *list, int pos){ ListElement * getElementPos(List *list, int pos){
ListElement * el = list->head; ListElement * el = list->head;
while (el != NULL && el->pos != pos){ while (el != NULL && el->pos != pos){
el = el->next; el = el->next;
@ -227,19 +227,19 @@ ListElement * GetElementPos(List *list, int pos){
return el; return el;
} }
int RemoveElementPos(List *list, int pos){ int removeElementPos(List *list, int pos){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *toDelete = GetElementPos(list, pos); ListElement *toDelete = getElementPos(list, pos);
if (toDelete != NULL){ if (toDelete != NULL){
ok = PopPtnList(list, toDelete); ok = popPtnList(list, toDelete);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }
return ok; return ok;
} }
int InsertBeforeElement(List *list, ListElement *eli, ListElement *elp){ int insertBeforeElement(List *list, ListElement *eli, ListElement *elp){
int ok = SUCCESS; int ok = SUCCESS;
if (list != NULL){ if (list != NULL){
@ -260,7 +260,7 @@ int InsertBeforeElement(List *list, ListElement *eli, ListElement *elp){
return ok; return ok;
} }
int InsertAfterElement(List *list, ListElement *eli, ListElement *elb){ int insertAfterElement(List *list, ListElement *eli, ListElement *elb){
int ok = SUCCESS; int ok = SUCCESS;
if (list != NULL){ if (list != NULL){
@ -281,16 +281,16 @@ int InsertAfterElement(List *list, ListElement *eli, ListElement *elb){
return ok; return ok;
} }
int InsertBefore(List *list, cellElement *data, int nb){ int insertBefore(List *list, cellElement *data, int nb){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *newElement = NULL; ListElement *newElement = NULL;
ListElement *eli = GetElement(list, nb); ListElement *eli = getElement(list, nb);
if (eli != NULL){ if (eli != NULL){
newElement = malloc(sizeof(*newElement)); newElement = malloc(sizeof(*newElement));
if (newElement != NULL){ if (newElement != NULL){
newElement->pos = -1; newElement->pos = -1;
newElement->data = data; newElement->data = data;
ok = InsertBeforeElement(list, newElement, eli); ok = insertBeforeElement(list, newElement, eli);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }
@ -300,16 +300,16 @@ int InsertBefore(List *list, cellElement *data, int nb){
return ok; return ok;
} }
int InsertAfter(List *list, cellElement *data, int nb){ int insertAfter(List *list, cellElement *data, int nb){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *newElement = NULL; ListElement *newElement = NULL;
ListElement *elb = GetElement(list, nb); ListElement *elb = getElement(list, nb);
if (elb != NULL){ if (elb != NULL){
newElement = malloc(sizeof(*newElement)); newElement = malloc(sizeof(*newElement));
if (newElement != NULL){ if (newElement != NULL){
newElement->pos = -1; newElement->pos = -1;
newElement->data = data; newElement->data = data;
ok = InsertAfterElement(list, newElement, elb); ok = insertAfterElement(list, newElement, elb);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }
@ -319,16 +319,16 @@ int InsertAfter(List *list, cellElement *data, int nb){
return ok; return ok;
} }
int InsertBeforePos(List *list, cellElement *data, int pos){ int insertBeforePos(List *list, cellElement *data, int pos){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *newElement = NULL; ListElement *newElement = NULL;
ListElement *eli = GetElementPos(list, pos); ListElement *eli = getElementPos(list, pos);
if (eli != NULL){ if (eli != NULL){
newElement = malloc(sizeof(*newElement)); newElement = malloc(sizeof(*newElement));
if (newElement != NULL){ if (newElement != NULL){
newElement->pos = -1; newElement->pos = -1;
newElement->data = data; newElement->data = data;
ok = InsertBeforeElement(list, newElement, eli); ok = insertBeforeElement(list, newElement, eli);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }
@ -338,16 +338,16 @@ int InsertBeforePos(List *list, cellElement *data, int pos){
return ok; return ok;
} }
int InsertAfterPos(List *list, cellElement *data, int pos){ int insertAfterPos(List *list, cellElement *data, int pos){
int ok = SUCCESS; int ok = SUCCESS;
ListElement *newElement = NULL; ListElement *newElement = NULL;
ListElement *elb = GetElementPos(list, pos); ListElement *elb = getElementPos(list, pos);
if (elb != NULL){ if (elb != NULL){
newElement = malloc(sizeof(*newElement)); newElement = malloc(sizeof(*newElement));
if (newElement != NULL){ if (newElement != NULL){
newElement->pos = -1; newElement->pos = -1;
newElement->data = data; newElement->data = data;
ok = InsertAfterElement(list, newElement, elb); ok = insertAfterElement(list, newElement, elb);
} else { } else {
ok = FAILURE; ok = FAILURE;
} }

View File

@ -62,7 +62,7 @@ typedef struct List {
* *
* @return List a pointer of list * @return List a pointer of list
*/ */
List * CreateList(); List * createList();
/** /**
* Insert an element at the begining of a list * Insert an element at the begining of a list
@ -86,7 +86,7 @@ int push(List* list, cellElement* data);
* @param nb the number of the element (can be negative) * @param nb the number of the element (can be negative)
* @return List an element * @return List an element
*/ */
ListElement * GetElement(List *list, int nb); ListElement * getElement(List *list, int nb);
/** /**
* Delete an element with a pointer of element in the list * Delete an element with a pointer of element in the list
@ -94,7 +94,7 @@ ListElement * GetElement(List *list, int nb);
* @param element of the list as a pointer * @param element of the list as a pointer
* @return int status of the operation * @return int status of the operation
*/ */
int PopPtnList(List *list, ListElement *element); int popPtnList(List *list, ListElement *element);
/** /**
* Delete an element with a position in the list * Delete an element with a position in the list
@ -102,7 +102,7 @@ int PopPtnList(List *list, ListElement *element);
* @param nb position of the element * @param nb position of the element
* @return int status of the operation * @return int status of the operation
*/ */
int RemoveElement(List *list, int nb); int removeElement(List *list, int nb);
/** /**
* Delete the first element of the list * Delete the first element of the list
@ -123,14 +123,14 @@ int pop(List *list);
* @param list as a pointer * @param list as a pointer
* @return int status of the operation * @return int status of the operation
*/ */
int DeleteListContent(List *list); int deleteListContent(List *list);
/** /**
* Free a list * Free a list
* @param list as a pointer * @param list as a pointer
* @return int status of the operation * @return int status of the operation
*/ */
int FreeList(List *list); int freeList(List *list);
/** /**
* Find the first element with the given pos value * Find the first element with the given pos value
@ -138,7 +138,7 @@ int FreeList(List *list);
* @param pos the pos value to find * @param pos the pos value to find
* @return ListElement the found element can return NULL * @return ListElement the found element can return NULL
*/ */
ListElement * GetElementPos(List *list, int pos); ListElement * getElementPos(List *list, int pos);
/** /**
* Delete the first element of a list with the given pos * Delete the first element of a list with the given pos
@ -146,7 +146,7 @@ ListElement * GetElementPos(List *list, int pos);
* @param pos pos value of the element * @param pos pos value of the element
* @return int status of the operation * @return int status of the operation
*/ */
int RemoveElementPos(List *list, int pos); int removeElementPos(List *list, int pos);
/** /**
* Insert an element in a list before the given element * Insert an element in a list before the given element
@ -155,7 +155,7 @@ int RemoveElementPos(List *list, int pos);
* @param elp the previous element in the list * @param elp the previous element in the list
* @return int status of the operation * @return int status of the operation
*/ */
int InsertBeforeElement(List *list, ListElement *eli, ListElement *elp); int insertBeforeElement(List *list, ListElement *eli, ListElement *elp);
/** /**
* Insert an element in a list after the given element * Insert an element in a list after the given element
@ -164,7 +164,7 @@ int InsertBeforeElement(List *list, ListElement *eli, ListElement *elp);
* @param elb the before element in the list * @param elb the before element in the list
* @return int status of the operation * @return int status of the operation
*/ */
int InsertAfterElement(List *list, ListElement *eli, ListElement *elb); int insertAfterElement(List *list, ListElement *eli, ListElement *elb);
/** /**
* Insert an element in a list before the given position * Insert an element in a list before the given position
@ -173,7 +173,7 @@ int InsertAfterElement(List *list, ListElement *eli, ListElement *elb);
* @param nb the position in list to find * @param nb the position in list to find
* @return int status of the operation * @return int status of the operation
*/ */
int InsertBefore(List *list, cellElement *data, int nb); int insertBefore(List *list, cellElement *data, int nb);
/** /**
* Insert an element in a list after the given position * Insert an element in a list after the given position
@ -182,7 +182,7 @@ int InsertBefore(List *list, cellElement *data, int nb);
* @param nb the position in list to find * @param nb the position in list to find
* @return int status of the operation * @return int status of the operation
*/ */
int InsertAfter(List *list, cellElement *data, int nb); int insertAfter(List *list, cellElement *data, int nb);
/** /**
* Insert an element in a list before the first element with the given pos * Insert an element in a list before the first element with the given pos
@ -191,7 +191,7 @@ int InsertAfter(List *list, cellElement *data, int nb);
* @param pos the first pos in list to find * @param pos the first pos in list to find
* @return int status of the operation * @return int status of the operation
*/ */
int InsertBeforePos(List *list, cellElement *data, int pos); int insertBeforePos(List *list, cellElement *data, int pos);
/** /**
* Insert an element in a list after the first element with the given pos * Insert an element in a list after the first element with the given pos
@ -200,6 +200,6 @@ int InsertBeforePos(List *list, cellElement *data, int pos);
* @param pos the first pos in list to find * @param pos the first pos in list to find
* @return int status of the operation * @return int status of the operation
*/ */
int InsertAfterPos(List *list, cellElement *data, int pos); int insertAfterPos(List *list, cellElement *data, int pos);
#endif /* LIST_H */ #endif /* LIST_H */

View File

@ -67,8 +67,8 @@ Matrix CreateMatrix(){
Matrix matrix; Matrix matrix;
matrix.colCount = 0; matrix.colCount = 0;
matrix.rowCount = 0; matrix.rowCount = 0;
matrix.cols = CreateList(); matrix.cols = createList();
matrix.rows = CreateList(); matrix.rows = createList();
return matrix; return matrix;
} }
@ -91,7 +91,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
elem = CreateCellElem(); elem = CreateCellElem();
SetPositionIndex(elem,ColPos,RowPos); SetPositionIndex(elem,ColPos,RowPos);
Row = GetElementPos(matrix.rows,RowPos); Row = getElementPos(matrix.rows,RowPos);
if (Row != NULL && Row->data != NULL){ if (Row != NULL && Row->data != NULL){
if (Row->data->colIndex == ColPos){ if (Row->data->colIndex == ColPos){
@ -117,7 +117,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){
matrix.rows->tail->pos = RowPos; matrix.rows->tail->pos = RowPos;
} }
Col = GetElementPos(matrix.cols,ColPos); Col = getElementPos(matrix.cols,ColPos);
if (Col != NULL && Col->data != NULL){ if (Col != NULL && Col->data != NULL){
if (Col->data->rowIndex == RowPos){ if (Col->data->rowIndex == RowPos){
@ -157,7 +157,7 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){
ListElement * Row = NULL; ListElement * Row = NULL;
cellElement * elem = NULL; cellElement * elem = NULL;
Row = GetElementPos(matrix.rows,RowPos); Row = getElementPos(matrix.rows,RowPos);
if (Row == NULL){ if (Row == NULL){
return NULL; return NULL;
} }
@ -182,12 +182,12 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
return 0; return 0;
} }
Row = GetElementPos(matrix.rows,RowPos); Row = getElementPos(matrix.rows,RowPos);
if (Row == NULL){ if (Row == NULL){
return -1; return -1;
} }
if (Row->data == NULL){ if (Row->data == NULL){
RemoveElementPos(matrix.rows,RowPos); removeElementPos(matrix.rows,RowPos);
return -1; return -1;
} }
@ -206,16 +206,16 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
} }
if (Row->data == NULL){ if (Row->data == NULL){
RemoveElementPos(matrix.rows,RowPos); removeElementPos(matrix.rows,RowPos);
} }
Col = GetElementPos(matrix.cols,ColPos); Col = getElementPos(matrix.cols,ColPos);
if (Col == NULL){ if (Col == NULL){
return -2; return -2;
} }
if (Col->data == NULL){ if (Col->data == NULL){
RemoveElementPos(matrix.cols,ColPos); removeElementPos(matrix.cols,ColPos);
return -1; return -1;
} }
if (Col->data->rowIndex == RowPos){ if (Col->data->rowIndex == RowPos){
@ -232,7 +232,7 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){
} }
} }
if (Col->data == NULL){ if (Col->data == NULL){
RemoveElementPos(matrix.cols,ColPos); removeElementPos(matrix.cols,ColPos);
} }
FreeCellElement(elem); FreeCellElement(elem);
@ -306,8 +306,8 @@ Matrix freeMatrix(Matrix matrix){
} }
FreeList(matrix.cols); freeList(matrix.cols);
FreeList(matrix.rows); freeList(matrix.rows);
return matrix; return matrix;
} }
@ -621,7 +621,7 @@ bool isColumnEmpty(Matrix matrix,int nb){
return true; return true;
} }
Col = GetElementPos(matrix.cols,nb); Col = getElementPos(matrix.cols,nb);
if (Col == NULL || Col->data == NULL){ if (Col == NULL || Col->data == NULL){
return true; return true;
} }
@ -638,7 +638,7 @@ bool isRowEmpty(Matrix matrix,int nb){
if (matrix.cols->size == 0 || matrix.rows->size == 0){ if (matrix.cols->size == 0 || matrix.rows->size == 0){
return true; return true;
} }
Row = GetElementPos(matrix.rows,nb); Row = getElementPos(matrix.rows,nb);
if (Row == NULL || Row->data == NULL){ if (Row == NULL || Row->data == NULL){
return true; return true;
} }