Mise à jour de 'DEV1.1/TP15/file.c'

This commit is contained in:
Simon SAYE BABU 2023-01-11 14:17:24 +01:00
parent e4498c21e7
commit bfdbf7a373

View File

@ -1,56 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pile
{
int tete;
char ple[10];
struct pile{
char val;
struct pile *suite;
};
typedef struct pile pile;
int empty(pile *p)
{
if(p==NULL)
{
return 1;
}
return p->tete==0;
int empty(pile* p){
return p==NULL;
}
char pop(pile **p)
{
(*p)->tete--;
return (*p)->ple[(*p)->tete];
}
void push(pile **p,char v)
{
if (*p==NULL)
{
void push(pile **p, char v){
pile *new=malloc(sizeof(pile));
new->tete=0;
new->val=v;
new->suite=*p;
*p=new;
push(p,v);
}else
{
(*p)->ple[(*p)->tete]=v;
(*p)->tete++;
}
}
char top(pile **p)
{
char temp = pop(p);
push(p,temp);
return temp;
char pop(pile **p){
char v=(*p)->val;
pile *temp=*p;
*p=(*p)->suite;
free(temp);
return v;
}
void clear(pile **p)
{
while(!empty((*p)))
{
void clear(pile **p){
while(!empty(*p)){
pop(p);
}
}
char top(pile **p){
return (*p)->val;
}