Skip to content
Snippets Groups Projects
Commit f0bea494 authored by leo.harb's avatar leo.harb
Browse files

terminé

parent da140b1c
No related branches found
No related tags found
No related merge requests found
// lien du git : https://githepia.hesge.ch/leo.harb/examen_programmation_2023 // lien du git : https://githepia.hesge.ch/leo.harb/examen_programmation_2023
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct element_t typedef struct element_t
{ {
struct element_t *prev; int value;
float value;
struct element_t *next; struct element_t *next;
} element; } element;
...@@ -14,14 +15,159 @@ typedef struct ll_t ...@@ -14,14 +15,159 @@ typedef struct ll_t
element *pos; element *pos;
}ll; }ll;
ll ll_create(){
ll res;
res.head = NULL;
res.pos = NULL;
return res;
}
void ll_destroy(ll *list){
list->pos = list->head;
while (list->pos != NULL)
{
element *tmp = list->pos->next;
free(list->pos);
list->pos = tmp;
}
list->head = NULL;
list->pos = NULL;
}
bool ll_is_empty(ll list){
return list.head == NULL;
}
// Est-ce que pos est le 1er élément?
bool ll_is_head(ll list){
return list.pos == list.head;
}
// Est-ce que pos est le dernier élément?
bool ll_is_tail(ll list){
return list.pos->next == NULL;
}
// data est-elle dans la liste?
bool ll_is_present(ll list, float data){
while (list.pos->next != NULL)
{
if(list.pos->value == data){
return true;
}
list.pos = list.pos->next;
}
return false;
}
void ll_push(ll *list, int data){
element *el = (element*)malloc(sizeof(element));
el->value = data;
el->next = list->head;
list->head = el;
list->pos = el;
}
void ll_insert(ll *list, int data){
element *el = (element*)malloc(sizeof(element));
if(list->pos == list->head){
list->head = el;
}
el->next = list->pos;
element *tmp = list->head;
while (tmp->next!=list->pos);
{
tmp = tmp->next;
}
tmp->next = el;
}
// affiche la liste
void ll_print(ll *list){
while (list->pos != NULL)
{
printf("%f ", list->pos->value);
list->pos = list->pos->next;
}
}
bool ll_contains(ll *list, int data){
element* tmp = list->head;
while (tmp != NULL)
{
if(tmp->value == data){
return true;
}
}
return false;
}
void ll_sort_in(ll *list1, ll *list2, ll *res){
list1->pos = list1->head;
res->pos = res->head;
while (list1->pos != NULL)
{
if(!ll_contains(res, list1->pos->value)){
while (res->pos->value <= list1->pos->value)
{
res->pos = res->pos->next;
}
ll_insert(res, list1->pos->value);
}
list1->pos = list1->pos->next;
}
while (list2->pos != NULL)
{
if(!ll_contains(res, list2->pos->value)){
while (res->pos->value <= list2->pos->value)
{
res->pos = res->pos->next;
}
ll_insert(res, list2->pos->value);
}
list2->pos = list2->pos->next;
}
}
int main(){ int main(){
int len1 = 0; int len1 = 0;
int len2 = 0; int len2 = 0;
int c = 0,r = 0; float values1[256];
char cmd = 0; float values2[256];
char entry[10]; int left = 0;
printf("Etrez la liste 1:\n"); char string1[256];
scanf("%[^\n]%*c", entry); char string2[256];
sscanf(entry, "%d %s", &cmd, &c, &r);
printf("Entrez la liste 1:");
scanf("%[^\n]%*c", string1);
float temp1;
char *p1 = string1;
int cpt1 = 0;
while(sscanf(p, "%f%n", &temp1, &left) == 1) {
values1[cpt1] = temp1;
p += left;
cpt1++;
}
printf("Entrez la liste 2:");
scanf("%[^\n]%*c", string1);
float temp2;
char *p2 = string2;
int cpt2 = 0;
while(sscanf(p, "%f%n", &temp2, &left) == 1) {
values1[cpt1] = temp2;
p += left;
cpt1++;
}
ll list1 = ll_create();
ll list2 = ll_create();
ll res = ll_create();
dll_print(&list);
dll_destroy(&list);
return 0; return 0;
} }
\ No newline at end of file
...@@ -90,7 +90,7 @@ int main() { ...@@ -90,7 +90,7 @@ int main() {
int left = 0; int left = 0;
char string[256]; char string[256];
printf("Liste d'entiers: \n"); printf("Liste d'entiers: ");
scanf("%[^\n]%*c", string); scanf("%[^\n]%*c", string);
float temp; float temp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment