Commit dc05fed3 authored by Unknown's avatar Unknown
Browse files

Test merge

parents d4376c1c bb79e679
......@@ -25,7 +25,6 @@ int main()
lTest->tail = e2;
display(lTest);
if (DEBUG) printf("Initialization of an instance of List...\n\n");
List* default_list;
initialize(&default_list);
......@@ -81,7 +80,7 @@ int main()
break;
case TOKEN_RMX_LI_ALL:
destruct(default_list);
destruct(&default_list);
break;
}
......
......@@ -19,7 +19,7 @@ void initialize(List** list){
void insert_empty_list(List** list, char* str){
if (DEBUG) printf("INSERT_EMPTY_LIST\n");
if(*list) printf("cool\n");
if ((*list)->head || (*list)->tail){
printf("List is not empty... use another insert function.\n");
return;
......@@ -34,10 +34,8 @@ void insert_empty_list(List** list, char* str){
// Le brancher
int length = strlen(str), total = 0, i;
printf("str length : %d\n", length);
while(length > 0){
if (DEBUG) printf("WHILE\n");
i = 0;
Element* e = malloc(sizeof(Element));
e->data = malloc(sizeof(char)*N);
......@@ -56,27 +54,14 @@ void insert_empty_list(List** list, char* str){
else
(*list)->tail->next = e;
(*list)->tail = e;
if (DEBUG) printf("element while : %s\n", e->data);
}
if (DEBUG) printf("FLAG 2\n");
Element* e_vide = malloc(sizeof(Element));
e_vide->data = NULL;
e_vide->next = NULL;
(*list)->tail->next = e_vide;
(*list)->tail = e_vide;//tail doit pointer sur le dernier element
if (DEBUG) printf("FLAG 3\n");
/*Element* e = malloc(sizeof(Element));
char tmp[N];
strncpy(tmp, str, N);
e->data = malloc(sizeof(char)*N);
e->data = tmp;
e->next = NULL;
list->head = e;
list->tail = e;*/
if (DEBUG) printf("Data inserted : %s\n", (*list)->head->data);
}
......@@ -124,10 +109,83 @@ int insert_after_position(List* list, char* str, int p){
int remove_element(List* list, int p){
if (DEBUG) printf("REMOVE_ELEMENT\n");
if (!*list){
printf("List pointer is null.\n");
return -1;
}
if(p <= 0){
printf("The provided value for the position is incorrect.\n");
return -1;
}
int n = 1; // position du parcours
Element* e = list->head, suppr;
/*
e sera utilisé pour pointer la bonne position, suppr sera utilisé pour "manger le nombre" (désallocation)
e will be used to focus on the right place, suppr will be used to "eat the number"
*/
while(n < p){ // tant que l'on est pas arrivé au Pème chiffre
do{
e = e->next;
}while(e->data != NULL); // on parcoure la liste jusqu'au prochain nombre
suppr = e->next;
n++;
}
/* à ce niveau, on en est là :
P
| ##### | ##### | ¤¤¤¤¤ | ##### | ##### | ¤¤¤¤¤ |
^ ^
e suppr
*/
do{
e->next = suppr->next;
free(suppr->data);
free(suppr);
suppr = e->next;
}while(suppr->data != NULL);
if (suppr == list->tail){ // si c'était le dernier nombre de la liste
free(list->tail->data);
list->tail = e;
e->next = NULL;
free(suppr);
}
else{ // sinon on a supprimé au milieu de la liste
e->next = suppr->next;
free(suppr->data);
free(suppr);
}
return 0;
}
int compare(char* str1, char* str2){
if (DEBUG) printf("COMPARE\n");
if (!str1) return 2;
if (!str2) return 1;
char car1 = *str1, car2 = *str2;
int int1 = 0, int2 = 0, i = 0;
int length = strlen(str1) > strlen(str2) ? strlen(str2) : strlen(str1);
while(i < length){
int1 = int1*10+car1-'0';
int2 = int2*10+car2-'0';
i++;
car1 = *(str1+i);
car2 = *(str2+i);
}
// calcul des termes convertis en int
if (int1 >= int2)
return 1;
return 2;
}
int sort(List* list){
......@@ -153,6 +211,7 @@ void destruct(List** list){
if (!*list){
printf("List is already destroyed...\n");
return;
}
while((*list)->head->next != NULL){/*cetait pas la bonne condition*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment