Partage de codes sources - CodesWall.info
C
> Pile
Titre
Pile
Postée le
19-12-2009
Affichée
1897
Mini-lien
Description
Pile de type tableau, pouvant prendre n'importe quel type "d'objet"
Etat
Ne contient pas d'erreurs.
Code d'insertion
Options
Tweet
Téléchargement
#include <stdio.h>
#include <stdlib.h>
typedef
struct
{
int
ind_sommet
;
void
**
t
;
int
max
;
}
pile
;
void
initPile
(
pile
*
p
,
int
_max
)
{
p
->
max
=
_max
;
p
->
t
=
(
void
**
)
calloc
(
_max
,
sizeof
(
void
*
)
)
;
p
->
ind_sommet
=
0
;
}
int
isPleine
(
const
pile
*
p
)
{
return
p
->
max
<=
p
->
ind_sommet
;
}
int
isVide
(
const
pile
*
p
)
{
return
p
->
ind_sommet
<=
0
;
}
int
empiler
(
pile
*
p
,
void
*
elem
)
{
if
(
!
isPleine
(
p
)
)
{
p
->
t
[
p
->
ind_sommet
++
]
=
elem
;
return
0
;
}
return
-
1
;
/* Pile pleine */
}
void
*
depiler
(
pile
*
p
)
{
if
(
!
isVide
(
p
)
)
return
p
->
t
[
--
(
p
->
ind_sommet
)
]
;
return
0
;
}
int
main
(
)
{
pile p
;
int
premierElement
=
12
;
char
deuxiemeElement
=
'T'
;
double
troisiemeElement
=
42
.
f
;
short
quatriemeElement
=
2
;
double
receptionElement1
;
char
receptionElement2
;
int
receptionElement3
;
void
*
test
;
initPile
(
&
p
,
3
)
;
if
(
empiler
(
&
p
,
(
void
*
)
&
premierElement
)
!=
-
1
)
{
printf
(
"Empilement Ok
\n
"
)
;
}
else
printf
(
"Empilement Erreur
\n
"
)
;
if
(
empiler
(
&
p
,
(
void
*
)
&
deuxiemeElement
)
!=
-
1
)
{
printf
(
"Empilement Ok
\n
"
)
;
}
else
printf
(
"Empilement Erreur
\n
"
)
;
if
(
empiler
(
&
p
,
(
void
*
)
&
troisiemeElement
)
!=
-
1
)
{
printf
(
"Empilement Ok
\n
"
)
;
}
else
printf
(
"Empilement Erreur
\n
"
)
;
if
(
empiler
(
&
p
,
(
void
*
)
&
quatriemeElement
)
!=
-
1
)
{
printf
(
"Empilement Ok
\n
"
)
;
}
else
printf
(
"Empilement Erreur
\n
"
)
;
receptionElement1
=
*
(
double
*
)
depiler
(
&
p
)
;
printf
(
"TEST1
\n
"
)
;
receptionElement2
=
*
(
char
*
)
depiler
(
&
p
)
;
printf
(
"TEST2
\n
"
)
;
receptionElement3
=
*
(
int
*
)
depiler
(
&
p
)
;
printf
(
"TEST3
\n
"
)
;
printf
(
"Voici les données transmises : %f, %c, %d"
,
receptionElement1
,
receptionElement2
,
receptionElement3
)
;
return
EXIT_SUCCESS
;
}
Postez votre code-source
Informations
Catégorie *
-
ActionScript3
ASP
C
C#.Net
C++
COBOL
CSS
Delphi
Fichier .ini
HTML4
HTML5
Java
javascript
jQuery
Latex
MatLab
mIRC
MySQL
Objective-C
OCaml
pascal
Perl
Php
Python
QBasic
Ruby
Script Batch
Shell
SmallTalk
VB.Net
VBA
Visual Basic
XML
Autre
Titre *
(50 car. max)
Description *
(200 car. max)
Le code
Fonctionne
Ne fonctionne pas
Je ne sais pas
Source
* : Champs obligatoires
Fermer
Accueil
Poster
Actualités
Règles
Contact
Partenaires
Infos / Aide
ActionScript3
(0)
ASP
(0)
C
(65)
C#.Net
(4)
C++
(51)
COBOL
(0)
CSS
(21)
Delphi
(0)
Fichier .ini
(5)
HTML4
(16)
HTML5
(2)
Java
(48)
javascript
(35)
jQuery
(0)
Latex
(6)
MatLab
(3)
mIRC
(3)
MySQL
(13)
Objective-C
(1)
OCaml
(4)
pascal
(9)
Perl
(11)
Php
(58)
Python
(3)
QBasic
(1)
Ruby
(1)
Script Batch
(8)
Shell
(10)
SmallTalk
(1)
VB.Net
(5)
VBA
(5)
Visual Basic
(6)
XML
(17)
Autre
(18)
\n
Forum informatique