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
Brian Longuet
TP Introduction à la sécurité L2
Commits
b57f42f0
Commit
b57f42f0
authored
3 years ago
by
Brian Longuet
Browse files
Options
Downloads
Patches
Plain Diff
fin du tp1
parent
6fcaad20
Branches
main
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/list.c
+79
-2
79 additions, 2 deletions
src/list.c
with
79 additions
and
2 deletions
src/list.c
+
79
−
2
View file @
b57f42f0
#include
<stdio.h>
#include
<stdlib.h>
struct
cell_t
{
void
*
val
;
unsigned
long
int
id
;
...
...
@@ -7,30 +11,103 @@ struct cell_t {
typedef
struct
cell_t
*
list_t
;
list_t
list_empty
(){
return
NULL
;
}
int
list_is_empty
(
list_t
l
){
int
list_is_empty
(
list_t
list
){
return
list
==
NULL
;
}
list_t
list_push
(
list_t
l
,
void
*
x
){
/*
list_t celule = malloc(sizeof(struct cell_t));
celule -> val = x;
if (list_is_empty(l) != 1){
celule -> id = l -> id + 1;
celule -> next = l;
}
else{
celule -> id = 1;
celule -> next = NULL;
}
return celule;
*/
list_t
celule
=
malloc
(
sizeof
(
struct
cell_t
));
celule
->
val
=
x
;
celule
->
next
=
l
;
if
(
list_is_empty
(
l
)){
celule
->
id
=
1
;
}
else
{
celule
->
id
=
l
->
id
+
1
;
}
return
celule
;
}
list_t
list_tail
(
list_t
l
){
if
(
list_is_empty
(
l
)){
return
NULL
;
}
return
l
->
next
;
}
void
*
list_pop
(
list_t
*
l
){
void
*
res
=
(
*
l
)
->
val
;
list_t
queue
=
(
*
l
)
->
next
;
free
(
*
l
);
*
l
=
queue
;
return
res
;
}
void
*
list_top
(
list_t
l
){
if
(
list_is_empty
(
l
)){
return
NULL
;
}
return
l
->
val
;
}
void
list_destroy
(
list_t
l
,
void
(
*
free_void
)(
void
*
)){
while
(
list_is_empty
(
l
)){
free_void
(
list_pop
(
&
l
));
}
void
list_destroy
(
list_t
l
,
void
(
*
free
)(
void
*
)){
}
// return the found element or NULL
void
*
list_in
(
list_t
l
,
void
*
x
,
int
(
*
eq
)(
void
*
,
void
*
)){
/*list_t tmp = l;
while(tmp != NULL){
if (eq(tmp->val,x)){
return tmp->val;
}
tmp = tmp -> next;
}
return NULL;*/
for
(
list_t
curr
=
l
;
!
list_is_empty
(
curr
);
curr
=
curr
->
next
)
if
(
eq
(
curr
->
val
,
x
))
return
curr
->
val
;
return
NULL
;
}
unsigned
long
int
list_len
(
list_t
l
){
if
(
list_empty
(
l
)){
return
0
;
}
return
l
->
id
;
}
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