Commit d2b106fe authored by William Sha's avatar William Sha
Browse files

Implemented compare function

Unit tests already done.
parent 54bb422e
......@@ -127,6 +127,26 @@ int remove_element(List* list, int p){
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){
......@@ -154,7 +174,7 @@ void destruct(List** list){
printf("List is already destroyed...\n");
}
while((*list)->head != NULL){
while((*list)->head != (*list)->tail){
printf("while\n");
Element* e = (*list)->head;
printf("pointeurs : list head : %p, e : %p\n", (*list)->head, e);
......
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