Skip to content
Snippets Groups Projects
Commit 0abd6ceb authored by william.ho's avatar william.ho
Browse files

ex1 pas reussi

parent 4a7533fe
No related branches found
No related tags found
No related merge requests found
ex1/main 0 → 100755
File added
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct _element { // Elément de liste
int data;
struct _element* next;
} element_t;
void free_liste(element_t* liste1){
element_t* prec = liste1;
element_t* current = liste1;
while(current->next != NULL){
prec = current;
current = current->next;
free(prec);
}
free(current);
}
void add_liste(element_t* liste, int val){
element_t* new = malloc(sizeof(element_t));
new->data = val;
new->next = NULL;
element_t* current = liste;
while(current->next != NULL ){
current = current->next;
}
current->next = new;
}
void print_liste(element_t* liste){
if(liste != NULL){
element_t* current = liste;
while(current->next != NULL){
printf("%d, ", current->data);
current = current->next;
}
printf("%d \n", current->data);
}else{
printf("Empty liste \n");
}
}
bool is_in_liste(element_t* liste, int x){
if(liste != NULL){
element_t* current = liste;
while(current->next != NULL){
if(current->x == x){
return current;
}
current = current->next;
}
}else{
return liste;
}
}
bool is_tri(element_t* liste){
element_t* current = liste;
element_t* prec = liste;
while(current != NULL){
if(current->data > prec->data){
return false;
}
prec = current;
current = current->next;
}
return true;
}
void tri_list(element_t* liste){
element_t* current = liste->next;
element_t* prec = liste;
element_t* prec2 = liste;
while(!is_tri(liste)){
while(current != NULL){
if(current->data > prec->data){
prec->next = current->next
}if(current->data == prec->data){
prec->next = current->next;
free(current);
current = prec->next;
}else{
}
prec2 = prec;
prec = current;
current = current->next;
}
}
}
element_t* tri_double_list(element_t* liste1, element_t* liste2){
element_t* current1 = liste1->next;
element_t* current2 = liste2;
element_t* new = malloc(sizeof(element_t));
new->data = liste1->data;
new->NULL;
element_t* new_index = new;
while(current1 != NULL){
add_liste(new, current1->data);
current1 = current1->next;
}
while(current2 != NULL){
add_liste(new, current1->data);
current2 = current2->next;
}
return new;
}
int main(){ int main(){
int size, tmp;
element_t* liste1 = malloc(sizeof(element_t));
element_t* liste2 = malloc(sizeof(element_t));
printf("Entrez la liste 1 : ");
scanf("%d", &size);
scanf("%d", &tmp);
liste1->data = tmp;
liste1->next = NULL;
size--;
while(size > 0){
scanf("%d", &tmp);
add_liste(liste1, tmp);
size --;
}
printf("Entrez la liste 2 : ");
scanf("%d", &size);
scanf("%d", &tmp);
liste2->data = tmp;
liste2->next = NULL;
size--;
while(size > 0){
scanf("%d", &tmp);
add_liste(liste2, tmp);
size --;
}
free_liste(liste1);
free_liste(liste2);
printf("Hello word\n");
return(0); return(0);
} }
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment