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
Emilien Blondeau
TP Introduction à la sécurité L2
Commits
c8169c1a
Commit
c8169c1a
authored
3 years ago
by
Emilien Blondeau
Browse files
Options
Downloads
Patches
Plain Diff
oui
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
+60
-10
60 additions, 10 deletions
src/list.c
src/list.h
+1
-0
1 addition, 0 deletions
src/list.h
tests/list_tests.c
+12
-12
12 additions, 12 deletions
tests/list_tests.c
with
73 additions
and
22 deletions
src/list.c
+
60
−
10
View file @
c8169c1a
struct
cell_t
{
void
*
val
;
unsigned
long
int
id
;
struct
cell_t
*
next
;
};
typedef
struct
cell_t
*
list_t
;
#include
<stdlib.h>
#include
<stdio.h>
#include
"list.h"
list_t
list_empty
(){
list_t
res
=
NULL
;
return
res
;
}
int
list_is_empty
(
list_t
l
){
if
(
l
==
NULL
){
return
1
;
}
return
0
;
}
list_t
list_push
(
list_t
l
,
void
*
x
){
list_t
res
=
malloc
(
sizeof
(
struct
cell_t
));
if
(
list_is_empty
(
l
)
==
1
){
res
->
val
=
x
;
res
->
next
=
NULL
;
res
->
id
=
1
;
return
res
;
}
res
->
val
=
x
;
res
->
next
=
l
;
res
->
id
=
l
->
id
+
1
;
return
res
;
}
list_t
list_tail
(
list_t
l
){
if
(
list_is_empty
(
l
)
==
0
){
return
l
->
next
;
}
return
NULL
;
}
void
*
list_pop
(
list_t
*
l
){
if
(
list_is_empty
(
l
)
==
0
){
list_t
tmp
=
(
*
l
);
(
*
l
)
=
(
*
l
)
->
next
;
void
*
res
=
tmp
->
val
;
free
(
tmp
);
return
res
;
}
return
NULL
;
}
void
*
list_top
(
list_t
l
){
if
(
list_is_empty
(
l
)
==
0
){
return
l
->
val
;
}
return
NULL
;
}
void
list_destroy
(
list_t
l
,
void
(
*
free
)(
void
*
)){
void
list_destroy
(
list_t
l
,
void
(
*
free_void
)(
void
*
)){
while
(
list_is_empty
(
l
)
==
0
){
free_void
(
l
->
val
);
list_t
tmp
=
l
;
l
=
l
->
next
;
free
(
tmp
);
}
}
// return the found element or NULL
void
*
list_in
(
list_t
l
,
void
*
x
,
int
(
*
eq
)(
void
*
,
void
*
)){
if
(
list_is_empty
(
l
)
==
0
){
while
(
l
->
id
!=
1
){
if
(
eq
(
l
->
val
,
x
)
==
0
){
return
l
->
val
;
}
l
=
l
->
next
;
}
}
return
NULL
;
}
unsigned
long
int
list_len
(
list_t
l
){
if
(
list_is_empty
(
l
)
==
0
){
return
l
->
id
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
src/list.h
+
1
−
0
View file @
c8169c1a
...
...
@@ -9,6 +9,7 @@ struct cell_t {
typedef
struct
cell_t
*
list_t
;
list_t
list_empty
();
int
list_is_empty
(
list_t
);
list_t
list_push
(
list_t
,
void
*
);
...
...
This diff is collapsed.
Click to expand it.
tests/list_tests.c
+
12
−
12
View file @
c8169c1a
#include
<assert.h>
#include
<stdio.h>
#include
"
linked_
list.h"
#include
"list.h"
#include
"bignum.h"
void
test_emptyness
()
{
...
...
@@ -29,7 +29,7 @@ void test_push(){
l
=
list_push
(
l
,
y
);
l
=
list_push
(
l
,
x
);
l
=
list_push
(
l
,
z
);
printf
(
"Oui
\n
"
);
assert
(
eq
(
list_top
(
l
),
z
));
assert
(
eq
(
list_top
(
list_tail
(
l
)),
x
));
assert
(
eq
(
list_top
(
list_tail
(
list_tail
(
l
))),
y
));
...
...
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