Commit d833f449 authored by Unknown's avatar Unknown
Browse files

Auto stash before merge of "master" and "origin/master"

inser position p 
but bug in a display just after adding 
parent ba3027cb
......@@ -8,6 +8,7 @@ int main()
int action = 0; // represents the choice of the user
char str_number[100];
int p = 0;
//char test[5];
printf("*****CHAINED LISTS*****\n");
......@@ -55,14 +56,9 @@ int main()
break;
case TOKEN_DEL_NB_SPC:
printf("What number do you want to remove ? ");
scanf("%s", str_number);
while(atoi(str_number) <= 0){
fflush(stdin);
printf("Wrong input. Please enter a positive position : ");
scanf("%s", str_number);
}
remove_element(default_list, atoi(str_number));
printf("what element do you want to remove?\n");
scanf("%d", &p);
remove_element(default_list, p);
break;
case TOKEN_SRT_LI_ASC:
......
......@@ -101,8 +101,31 @@ void insert_end_list(List** list, char* str){
}
int insert_after_position(List* list, char* str, int p){
int insert_after_position(List** list, char* str, int p){
if (DEBUG) printf("INSERT_AFTER_POSITION\n");
if (!(*list)){
printf("List doesn't exist.\n");
return -1;
}
if(p <= 0){
printf("The provided value for the position is incorrect.\n");
return -1;
}
if (((*list)->head == (*list)->tail) & ((*list)->head == NULL)){
insert_beginning_list(list, str);
}
if (((*list)->head != NULL) & ((*list)->head == (*list)->tail)){
insert_end_list(list, str);
}
int n = 1; // position du parcours
Element* e = (*list)->head;
Element* add;
}
int remove_element(List* list, int p){
......@@ -126,7 +149,8 @@ int remove_element(List* list, int p){
e sera utilisé pour pointer la bonne position, suppr sera utilisé pour "manger le nombre" (désallocation)
*/
while(n < p){ // tant que l'on est pas arrivé au Pème chiffre
while(n <= p){ // tant que l'on est pas arrivé au Pème chiffre
if (DEBUG) printf("WHILE\n");
do{
e = e->next;
}while(e->data != NULL); // on parcoure la liste jusqu'au prochain nombre
......@@ -209,6 +233,12 @@ void display(List* list){
printf("Nothing to display...\n");
return;
}
int c;
c = lenghtList(list);
printf("length list : %d", c);
Element *p = list->head;
for (p = list->head; p != NULL; p = p->next){
printf("element: %s\n ", p->data);
......@@ -261,3 +291,21 @@ void display_menu(){
}
int lenghtList (List *list){
if(!list){
printf("list doesn't exist");
return -1;
}
Element *parcour = list->head;
int compteur = 0;
while(parcour != list->tail){
parcour = parcour->next;
if(parcour->data == NULL)
compteur++;
}
return compteur;
}
......@@ -23,7 +23,7 @@ void initialize(List** list);
void insert_empty_list(List** list, char* str);
void insert_beginning_list(List** list, char* str);
void insert_end_list(List** list, char* str);
int insert_after_position(List* list, char* str, int p);
int insert_after_position(List** list, char* str, int p);
int remove_element(List* list, int p);
int compare(char* str1, char* str2);
int sort(List* list);
......@@ -31,3 +31,4 @@ void display(List* list);
void destruct(List** list);
void display_menu();
int lenghtList (List *list);
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