Compare commits

..

No commits in common. "925c42ba2c08575339d3b9841cf74ec98b30354c" and "2e7253c43c8e65a98686582d853147831016103f" have entirely different histories.

2 changed files with 36 additions and 92 deletions

View file

@ -19,100 +19,52 @@ struct queue {
typedef struct queue *Pqueue; typedef struct queue *Pqueue;
/** /**
* @brief create an empty element of queue * @brief Create Element of queue
* *
* @return Pqueue * @param lenChar size of char array that will be created
* @return Pqueue new element created
*/ */
Pqueue queueCreateEmpty(){ Pqueue createE(int lenChar){
Pqueue new = (Pqueue) malloc(sizeof(struct queue)); Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new); assert(new);
new->charLen = 0; /* ???? tab char create or give pointer ???*/
new->tabChar = NULL; new->charLen = lenChar;
new->tabChar = (char *) malloc(lenChar * sizeof(char));
new->pNextE = NULL; new->pNextE = NULL;
return new; return new;
} }
/************ SETTER ************/
/**
* @brief set char size array
*
* @param elem targeted element
* @param _charLen size of char array
* @return Pqueue
*/
Pqueue queueSetCharLen(Pqueue elem, int _charLen){
assert(elem);
elem->charLen = _charLen;
}
/**
* @brief set the char array in the element
*
* @param elem targeted element
* @param _charLen char array size
* @param _tabChar pointer to static char array
* @return Pqueue
*/
Pqueue queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){
assert(elem);
assert(_tabChar);
elem->charLen = _charLen;
elem->tabChar = (char *) malloc(_charLen * sizeof(char));
for(int i = 0; i < _charLen; i++){
new->tabChar[i] = _tabChar[i];
}
}
/************ GETTER ************/
/** /**
* @brief switch to the next element * @brief switch to the next element
* *
* @param elem current element * @param elem current element
* @return Pqueue next element * @return Pqueue next element
*/ */
Pqueue queueGetNextE(Pqueue elem){ Pqueue getNextE(Pqueue elem){
assert(elem); assert(elem);
return elem->pNextE; return elem->pNextE;
} }
/** int getCharLen(Pqueue elem){
* @brief get the size char array
*
* @param elem targeted element
* @return int
*/
int queueGetCharLen(Pqueue elem){
assert(elem); assert(elem);
return elem->charLen; return elem->charLen;
} }
/** char * gettabChar(Pqueue elem){
* @brief get the pointer of char array
*
* @param elem targeted elemnt
* @return char*
*/
char * queueGetTabChar(Pqueue elem){
assert(elem); assert(elem);
return elem->tabChar; return elem->tabChar;
} }
/************ ************/ void setCharLen(Pqueue elem , int _charLen){
assert(elem);
elem->charLen = _charLen;
}
/** void setTabChar(Pqueue elem , int _charLen , char *_tabChar){
* @brief Create Element of queue assert(elem);
* elem->charLen = _charLen;
* @param lenChar size of char array that will be created elem->tabChar = (char *) malloc(_charLen * sizeof(char));
* @return Pqueue new element created elem->tabChar = _tabChar;
*/
Pqueue queueCreateE(int lenChar, const char* _tabChar){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new);
queueSetTabChar(new, lenChar, _tabChar);
new->pNextE = NULL;
return new;
} }
void setNextE(Pqueue elem , Pqueue next){ void setNextE(Pqueue elem , Pqueue next){
@ -127,12 +79,12 @@ void setNextE(Pqueue elem , Pqueue next){
* @param elem current element * @param elem current element
* @return Pqueue current element * @return Pqueue current element
*/ */
Pqueue queueRmLastE(Pqueue elem){ Pqueue rmLastE(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem, previous = NULL; Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){ while(elem->pNextE != NULL){
previous = tmp; previous = tmp;
tmp = queueGetNextE(tmp); tmp = getNextE(tmp);
} }
free(tmp->tabChar); free(tmp->tabChar);
free(tmp); free(tmp);
@ -146,7 +98,7 @@ Pqueue queueRmLastE(Pqueue elem){
* @param elem target to remove (the element need to be the first) * @param elem target to remove (the element need to be the first)
* @return Pqueue the second element after remove first * @return Pqueue the second element after remove first
*/ */
Pqueue queueRmFrstE(Pqueue elem){ Pqueue rmFrstE(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem->pNextE; Pqueue tmp = elem->pNextE;
free(elem->tabChar); free(elem->tabChar);
@ -160,10 +112,10 @@ Pqueue queueRmFrstE(Pqueue elem){
* @param elem * @param elem
* @return Pqueue * @return Pqueue
*/ */
Pqueue queueNextDelFrst(Pqueue elem){ Pqueue nextDelFrst(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem->pNextE; Pqueue tmp = elem->pNextE;
queueRmFrstE(elem); rmFrstE(elem);
return tmp; return tmp;
} }
@ -175,27 +127,23 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @param len the lenght of char array * @param len the lenght of char array
* @return Pqueue pointer to the last element * @return Pqueue pointer to the last element
*/ */
Pqueue queueAddLastQ(Pqueue elem, const char* str, int len){ Pqueue addLastQ(Pqueue elem, const char* str, int len){
assert(elem); assert(elem);
assert(str); assert(str);
Pqueue tmp = elem, previous = NULL; Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){ while(elem->pNextE != NULL){
previous = tmp; previous = tmp;
tmp = queueGetNextE(tmp); tmp = getNextE(tmp);
} }
tmp = queueCreateE(len); tmp -> pNextE = createE(len);
tmp->tabChar = str; Pqueue next = getNextE(tmp);
tmp->charLen = len; next->tabChar = str;
return tmp; next->charLen = len;
return next;
} }
/** void printE(Pqueue elem){
* @brief Print targeted element Pqueue next = getNextE(elem);
*
* @param elem targeted element
*/
void queuePrintE(Pqueue elem){
Pqueue next = queueGetNextE(elem);
printf("File Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen ); printf("File Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen );
if(next != NULL){ if(next != NULL){
printf("Next File : %s\n", next ->tabChar); printf("Next File : %s\n", next ->tabChar);

View file

@ -1,8 +1,9 @@
typedef struct queue *Pqueue; typedef struct queue *Pqueue;
//Constructors //Constructors
Pqueue createE(int lenChar, const char* _tabChar); Pqueue createE(int lenChar);
Pqueue createEmpty(); Pqueue createEEmpty(); //create a new element but all variables in are null, use to create the first element of the queue in the main before define the elements in
// constructeur avec 2 paramètres : strlen et tabchar
//Getters //Getters
Pqueue getNextE(Pqueue elem); Pqueue getNextE(Pqueue elem);
@ -10,15 +11,10 @@ Pqueue getNextE(Pqueue elem);
char * gettabChar(Pqueue elem); char * gettabChar(Pqueue elem);
//Setters //Setters
<<<<<<< HEAD
Pqueue setCharLen(Pqueue elem , int _charLen);
Pqueue setTabChar(Pqueue elem , int _charLen, const char *_tabChar);
=======
void setCharLen(Pqueue elem , int _charLen); void setCharLen(Pqueue elem , int _charLen);
void setTabChar(Pqueue elem , int _charLen , char *_tabChar); void setTabChar(Pqueue elem , int _charLen , char *_tabChar);
void setNextE(Pqueue elem , Pqueue next); void setNextE(Pqueue elem , Pqueue next);
>>>>>>> 2e7253c43c8e65a98686582d853147831016103f
Pqueue addLastQ(Pqueue elem, const char* str, int len); Pqueue addLastQ(Pqueue elem, const char* str, int len);
//Removers //Removers