Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP Introduction à la sécurité L2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Lou-Anne Gautherie
TP Introduction à la sécurité L2
Commits
a77d087e
Commit
a77d087e
authored
3 years ago
by
Lou-Anne Gautherie
Browse files
Options
Downloads
Patches
Plain Diff
Listes Chainees
parent
cc6bb2ce
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
src/list.c
+44
-4
44 additions, 4 deletions
src/list.c
tests/exemple_collision.c
+3
-3
3 additions, 3 deletions
tests/exemple_collision.c
tests/list_tests.c
+10
-10
10 additions, 10 deletions
tests/list_tests.c
with
57 additions
and
17 deletions
src/list.c
+
44
−
4
View file @
a77d087e
#include
<stdio.h>
#include
<stdlib.h>
struct
cell_t
{
void
*
val
;
unsigned
long
int
id
;
...
...
@@ -6,31 +9,68 @@ struct cell_t {
typedef
struct
cell_t
*
list_t
;
//Renvoie une liste vide
list_t
list_empty
(){
return
NULL
;
}
//Teste si la liste est vide
int
list_is_empty
(
list_t
l
){
return
l
==
NULL
;
}
//Ajoute et créé une nouvelle case
list_t
list_push
(
list_t
l
,
void
*
x
){
list_t
new
=
malloc
(
sizeof
(
struct
cell_t
));
new
->
val
=
x
;
if
(
list_is_empty
(
l
)){
new
->
id
=
1
;
}
else
{
new
->
id
=
l
->
id
+
1
;
}
new
->
next
=
l
;
return
new
;
}
//Renvoie la queue de la liste
list_t
list_tail
(
list_t
l
){
return
l
->
next
;
}
//Renvoie la première valeur
void
*
list_pop
(
list_t
*
l
){
list_t
tmp
=
(
*
l
)
->
next
;
void
*
res
=
(
*
l
)
->
val
;
free
(
*
l
);
*
l
=
tmp
;
return
res
;
}
//Renvoie la première valeur dans la première case
void
*
list_top
(
list_t
l
){
return
l
->
val
;
}
void
list_destroy
(
list_t
l
,
void
(
*
free
)(
void
*
)){
//Free sur toutes les cases et toutes les valeurs
void
list_destroy
(
list_t
l
,
void
(
*
free_void
)(
void
*
)){
while
(
!
list_is_empty
(
l
)){
free_void
(
list_pop
(
&
l
));
}
}
//
return the found element or
NULL
//
Renvoie l'élément trouvé ou
NULL
void
*
list_in
(
list_t
l
,
void
*
x
,
int
(
*
eq
)(
void
*
,
void
*
)){
while
(
l
!=
NULL
){
if
(
eq
(
l
->
val
,
x
)){
return
l
->
val
;
}
l
=
list_tail
(
l
);
}
return
NULL
;
}
//Renvoie la longueur de la liste
unsigned
long
int
list_len
(
list_t
l
){
return
l
->
id
;
}
This diff is collapsed.
Click to expand it.
tests/exemple_collision.c
+
3
−
3
View file @
a77d087e
...
...
@@ -43,8 +43,8 @@ int main(){
return
0
;
}
else
{
i
++
;
l
=
list_push
(
l
,
p
);
}
}
}
This diff is collapsed.
Click to expand it.
tests/list_tests.c
+
10
−
10
View file @
a77d087e
#include
<assert.h>
#include
<stdio.h>
#include
"
linked_
list.h"
#include
"list.h"
#include
"bignum.h"
void
test_emptyness
()
{
...
...
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