Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Exam2_prog_C
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
william.ho
Exam2_prog_C
Commits
0abd6ceb
Commit
0abd6ceb
authored
2 years ago
by
william.ho
Browse files
Options
Downloads
Patches
Plain Diff
ex1 pas reussi
parent
4a7533fe
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ex1/main
+0
-0
0 additions, 0 deletions
ex1/main
ex1/main.c
+154
-1
154 additions, 1 deletion
ex1/main.c
ex1/main.o
+0
-0
0 additions, 0 deletions
ex1/main.o
with
154 additions
and
1 deletion
ex1/main
0 → 100755
+
0
−
0
View file @
0abd6ceb
File added
This diff is collapsed.
Click to expand it.
ex1/main.c
+
154
−
1
View file @
0abd6ceb
#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
);
}
}
This diff is collapsed.
Click to expand it.
ex1/main.o
0 → 100644
+
0
−
0
View file @
0abd6ceb
File added
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