Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
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
joachim.bach
cours
Commits
0bf2e91e
Verified
Commit
0bf2e91e
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added pile in tableaux_1d
parent
c541b50f
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
source_codes/tableaux_1d/pile_array_int.c
+81
-0
81 additions, 0 deletions
source_codes/tableaux_1d/pile_array_int.c
source_codes/tableaux_1d/pile_array_int.h
+31
-0
31 additions, 0 deletions
source_codes/tableaux_1d/pile_array_int.h
with
112 additions
and
0 deletions
source_codes/tableaux_1d/pile_array_int.c
0 → 100644
+
81
−
0
View file @
0bf2e91e
#include
"pile_array_int.h"
#include
<assert.h>
#include
<limits.h>
#include
<stdbool.h>
#include
<stdlib.h>
bool
pile_est_valide
(
pile
stack
)
{
return
(
stack
.
capacite
>
0
&&
stack
.
sommet
>=
-
1
&&
stack
.
data
!=
NULL
);
}
bool
pile_est_vide
(
pile
stack
)
{
assert
(
pile_est_valide
(
stack
));
return
(
-
1
==
stack
.
sommet
);
}
bool
pile_est_pleine
(
pile
stack
)
{
assert
(
pile_est_valide
(
stack
));
return
(
stack
.
capacite
-
1
==
stack
.
sommet
);
}
int
pile_count
(
pile
stack
)
{
assert
(
pile_est_valide
(
stack
));
return
stack
.
sommet
+
1
;
}
int
pile_sommet
(
pile
stack
)
{
assert
(
!
pile_est_vide
(
stack
));
return
stack
.
data
[
stack
.
sommet
];
}
pile
pile_creer
(
int
max
)
{
assert
(
max
>
0
);
pile
stack
;
stack
.
capacite
=
max
;
stack
.
sommet
=
-
1
;
stack
.
data
=
malloc
(
max
*
sizeof
(
int
));
return
stack
;
}
void
pile_resize
(
pile
*
stack
,
int
max
)
{
assert
(
pile_est_valide
(
*
stack
));
if
(
max
>
stack
->
capacite
)
{
stack
->
capacite
=
max
;
stack
->
data
=
realloc
(
stack
->
data
,
max
*
sizeof
(
int
));
}
}
void
pile_detruire
(
pile
*
stack
)
{
stack
->
capacite
=
-
1
;
stack
->
sommet
=
INT_MIN
;
free
(
stack
->
data
);
stack
->
data
=
NULL
;
}
void
pile_empiler
(
pile
*
stack
,
int
val
)
{
if
(
pile_est_pleine
(
*
stack
))
{
pile_resize
(
stack
,
stack
->
capacite
+
INCR
);
}
stack
->
sommet
++
;
stack
->
data
[
stack
->
sommet
]
=
val
;
}
int
pile_depiler
(
pile
*
stack
)
{
int
val
=
pile_sommet
(
*
stack
);
stack
->
sommet
--
;
return
val
;
}
int
main
()
{
pile
p
=
pile_creer
(
10
);
pile_empiler
(
&
p
,
1
);
pile_empiler
(
&
p
,
10
);
assert
(
pile_sommet
(
p
)
==
10
);
assert
(
pile_depiler
(
&
p
)
==
10
);
assert
(
pile_depiler
(
&
p
)
==
1
);
assert
(
pile_est_vide
(
p
));
pile_detruire
(
&
p
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
source_codes/tableaux_1d/pile_array_int.h
0 → 100644
+
31
−
0
View file @
0bf2e91e
#ifndef PILE_ARRAY_INT_H
#define PILE_ARRAY_INT_H
#include
<stdbool.h>
const
int
INCR
=
100
;
typedef
struct
_pile
{
int
*
data
;
int
sommet
;
int
capacite
;
}
pile
;
// Créer une nouvelle pile vide
pile
pile_creer
(
int
max
);
// Libérer le tableau, mettre la capacité à < -1
void
pile_detruire
(
pile
*
stack
);
// Empiler un élement au sommet de pile
void
pile_empiler
(
pile
*
stack
,
int
val
);
// Dépiler un élément du sommet de la pile
int
pile_depiler
(
pile
*
stack
);
// Tester si la pile est vide
bool
pile_est_vide
(
pile
stack
);
// Tester si la pile est pleine
bool
pile_est_pleine
(
pile
stack
);
// Consulter l'élément au sommet de la pile
int
pile_sommet
(
pile
stack
);
// Compter du nombre d'éléments de la pile:
int
pile_count
(
pile
stack
);
#endif
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