Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Examen_programmation_2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leo.harb
Examen_programmation_2023
Commits
f0bea494
Commit
f0bea494
authored
2 years ago
by
leo.harb
Browse files
Options
Downloads
Patches
Plain Diff
terminé
parent
da140b1c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ex1/ex1.c
+154
-8
154 additions, 8 deletions
ex1/ex1.c
ex3/ex3.c
+1
-1
1 addition, 1 deletion
ex3/ex3.c
with
155 additions
and
9 deletions
ex1/ex1.c
+
154
−
8
View file @
f0bea494
// 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
This diff is collapsed.
Click to expand it.
ex3/ex3.c
+
1
−
1
View file @
f0bea494
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment