add createEmpty and modify struct queue
This commit is contained in:
parent
8c9de2d97d
commit
3e550297d6
111
Code-C/queue.c
111
Code-C/queue.c
|
@ -19,52 +19,100 @@ struct queue {
|
||||||
typedef struct queue *Pqueue;
|
typedef struct queue *Pqueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create Element of queue
|
* @brief create an empty element of queue
|
||||||
*
|
*
|
||||||
* @param lenChar size of char array that will be created
|
* @return Pqueue
|
||||||
* @return Pqueue new element created
|
|
||||||
*/
|
*/
|
||||||
Pqueue createE(int lenChar , char* _tabChar){
|
Pqueue queueCreateEmpty(){
|
||||||
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
|
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
|
||||||
assert(new);
|
assert(new);
|
||||||
/* ???? tab char create or give pointer ???*/
|
new->charLen = 0;
|
||||||
new->charLen = lenChar;
|
new->tabChar = NULL;
|
||||||
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 getNextE(Pqueue elem){
|
Pqueue queueGetNextE(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pqueue setCharLen(Pqueue elem , int _charLen){
|
/************ ************/
|
||||||
assert(elem);
|
|
||||||
elem->charLen = _charLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pqueue setTabChar(Pqueue elem , int _charLen , char *_tabChar){
|
/**
|
||||||
assert(elem);
|
* @brief Create Element of queue
|
||||||
elem->charLen = _charLen;
|
*
|
||||||
elem->tabChar = (char *) malloc(_charLen * sizeof(char));
|
* @param lenChar size of char array that will be created
|
||||||
elem->tabChar = _tabChar;
|
* @return Pqueue new element created
|
||||||
|
*/
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,12 +121,12 @@ Pqueue setTabChar(Pqueue elem , int _charLen , char *_tabChar){
|
||||||
* @param elem current element
|
* @param elem current element
|
||||||
* @return Pqueue current element
|
* @return Pqueue current element
|
||||||
*/
|
*/
|
||||||
Pqueue rmLastE(Pqueue elem){
|
Pqueue queueRmLastE(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 = getNextE(tmp);
|
tmp = queueGetNextE(tmp);
|
||||||
}
|
}
|
||||||
free(tmp->tabChar);
|
free(tmp->tabChar);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
@ -92,7 +140,7 @@ Pqueue rmLastE(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 rmFrstE(Pqueue elem){
|
Pqueue queueRmFrstE(Pqueue elem){
|
||||||
assert(elem);
|
assert(elem);
|
||||||
Pqueue tmp = elem->pNextE;
|
Pqueue tmp = elem->pNextE;
|
||||||
free(elem->tabChar);
|
free(elem->tabChar);
|
||||||
|
@ -106,10 +154,10 @@ Pqueue rmFrstE(Pqueue elem){
|
||||||
* @param elem
|
* @param elem
|
||||||
* @return Pqueue
|
* @return Pqueue
|
||||||
*/
|
*/
|
||||||
Pqueue nextDelFrst(Pqueue elem){
|
Pqueue queueNextDelFrst(Pqueue elem){
|
||||||
assert(elem);
|
assert(elem);
|
||||||
Pqueue tmp = elem->pNextE;
|
Pqueue tmp = elem->pNextE;
|
||||||
rmFrstE(elem);
|
queueRmFrstE(elem);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,22 +169,27 @@ Pqueue nextDelFrst(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 addLastQ(Pqueue elem, const char* str, int len){
|
Pqueue queueAddLastQ(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 = getNextE(tmp);
|
tmp = queueGetNextE(tmp);
|
||||||
}
|
}
|
||||||
tmp = createE(len);
|
tmp = queueCreateE(len);
|
||||||
tmp->tabChar = str;
|
tmp->tabChar = str;
|
||||||
tmp->charLen = len;
|
tmp->charLen = len;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printE(Pqueue elem){
|
/**
|
||||||
Pqueue next = getNextE(elem);
|
* @brief Print targeted element
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
typedef struct queue *Pqueue;
|
typedef struct queue *Pqueue;
|
||||||
|
|
||||||
//Constructors
|
//Constructors
|
||||||
Pqueue createE(int lenChar);
|
Pqueue createE(int lenChar, const char* _tabChar);
|
||||||
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
|
Pqueue createEmpty();
|
||||||
// constructeur avec 2 paramètres : strlen et tabchar
|
|
||||||
|
|
||||||
//Getters
|
//Getters
|
||||||
Pqueue getNextE(Pqueue elem);
|
Pqueue getNextE(Pqueue elem);
|
||||||
|
@ -12,7 +11,7 @@ char * gettabChar(Pqueue elem);
|
||||||
|
|
||||||
//Setters
|
//Setters
|
||||||
Pqueue setCharLen(Pqueue elem , int _charLen);
|
Pqueue setCharLen(Pqueue elem , int _charLen);
|
||||||
Pqueue setTabChar(Pqueue elem , int _charLen , char *_tabChar);
|
Pqueue setTabChar(Pqueue elem , int _charLen, const char *_tabChar);
|
||||||
Pqueue addLastQ(Pqueue elem, const char* str, int len);
|
Pqueue addLastQ(Pqueue elem, const char* str, int len);
|
||||||
|
|
||||||
//Removers
|
//Removers
|
||||||
|
|
Loading…
Reference in a new issue