update
This commit is contained in:
30
DEV/DEV1.1_suite/TP_Piles/Makefile~
Normal file
30
DEV/DEV1.1_suite/TP_Piles/Makefile~
Normal file
@@ -0,0 +1,30 @@
|
||||
# 1 : BUT FINAL
|
||||
|
||||
but : exe
|
||||
|
||||
# 2 : VARIABLES
|
||||
|
||||
OFILES = Pile_chainees.o \
|
||||
main.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -g
|
||||
|
||||
# 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||
|
||||
main.o : main.c Pile_chainees.h
|
||||
|
||||
#4 : DEPENDANCES AVEC COMMANDES
|
||||
|
||||
exe : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o exe $(OFILES)
|
||||
|
||||
#5 : NETTOYAGE DES FICHIERS GENERES
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) exe
|
||||
|
||||
#6 : BUTS FACTICES
|
||||
|
||||
.PHONY : but clean
|
30
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Makefile
Normal file
30
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
# 1 : BUT FINAL
|
||||
|
||||
but : exe
|
||||
|
||||
# 2 : VARIABLES
|
||||
|
||||
OFILES = tableau.o \
|
||||
main.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -g
|
||||
|
||||
# 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||
|
||||
main.o : main.c tableau.h
|
||||
|
||||
#4 : DEPENDANCES AVEC COMMANDES
|
||||
|
||||
exe : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o exe $(OFILES)
|
||||
|
||||
#5 : NETTOYAGE DES FICHIERS GENERES
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) exe
|
||||
|
||||
#6 : BUTS FACTICES
|
||||
|
||||
.PHONY : but clean
|
30
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Makefile~
Normal file
30
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Makefile~
Normal file
@@ -0,0 +1,30 @@
|
||||
# 1 : BUT FINAL
|
||||
|
||||
but : exe
|
||||
|
||||
# 2 : VARIABLES
|
||||
|
||||
OFILES = chaine.o \
|
||||
main.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -g
|
||||
|
||||
# 3 : DEPENDANCES (REGLES IMPLICITES)
|
||||
|
||||
main.o : main.c chaine.h
|
||||
|
||||
#4 : DEPENDANCES AVEC COMMANDES
|
||||
|
||||
exe : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o exe $(OFILES)
|
||||
|
||||
#5 : NETTOYAGE DES FICHIERS GENERES
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) exe
|
||||
|
||||
#6 : BUTS FACTICES
|
||||
|
||||
.PHONY : but clean
|
81
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_Tableau.c~
Normal file
81
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_Tableau.c~
Normal file
@@ -0,0 +1,81 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct pile{
|
||||
char* adresse;
|
||||
int taille;
|
||||
int capacite;
|
||||
} pile;
|
||||
|
||||
void creerPile(pile** p_pile){
|
||||
printf("1\n");
|
||||
(*p_pile)->capacite = 512;
|
||||
printf("2\n");
|
||||
(*p_pile)->taille = 0;
|
||||
printf("3\n");
|
||||
(*p_pile)->adresse = (char*) malloc((*p_pile)->capacite*sizeof(char));
|
||||
printf("4\n");
|
||||
}
|
||||
|
||||
int empty(pile* p_pile){
|
||||
if (p_pile->taille>0){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(pile** p_pile, char newValeur){
|
||||
if ((*p_pile)->taille == (*p_pile)->capacite){
|
||||
(*p_pile)->capacite *= 2;
|
||||
(*p_pile)->adresse = realloc((*p_pile)->adresse,(*p_pile)->capacite*sizeof(char));
|
||||
}
|
||||
(*p_pile)->adresse[(*p_pile)->taille] = newValeur;
|
||||
(*p_pile)->taille ++;
|
||||
}
|
||||
|
||||
char pop(pile** p_pile){
|
||||
(*p_pile)->taille --;
|
||||
return (*p_pile)->adresse[(*p_pile)->taille];
|
||||
}
|
||||
|
||||
char top(pile* p_pile){
|
||||
return p_pile->adresse[p_pile->taille-1];
|
||||
}
|
||||
|
||||
void clear(pile** p_pile){
|
||||
(*p_pile)->taille=0;
|
||||
}
|
||||
|
||||
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
pile* p_pile;
|
||||
creerPile(&p_pile);
|
||||
printf("\n----------instruction----------\n1<char>- push\n2- pop\n3- top\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",pop(&p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",top(p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_pile);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
free(p_pile->adresse);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
|
17
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_Tableau.h~
Normal file
17
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_Tableau.h~
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef PILE_CHAINEES_H
|
||||
#define PILE_CHAINEES_H
|
||||
|
||||
typedef struct pile{
|
||||
char* adresse;
|
||||
int taille;
|
||||
int capacite;
|
||||
} pile;
|
||||
|
||||
void creerPile(pile** p_pile);
|
||||
int empty(pile* p_pile);
|
||||
void push(pile** p_pile, char newValeur);
|
||||
char pop(pile** p_pile);
|
||||
char top(pile* p_pile);
|
||||
void clear(pile** p_pile);
|
||||
|
||||
#endif
|
82
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_chainees.c~
Normal file
82
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_chainees.c~
Normal file
@@ -0,0 +1,82 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct pile{
|
||||
maillon* adresse;
|
||||
}pile;
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
void creerPile(pile** p_pile){
|
||||
p_pile->adresse=NULL;
|
||||
}
|
||||
|
||||
int empty(pile* p_pile){
|
||||
if (p_pile->adresse){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(pile** p_pile, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = *p_pile;
|
||||
p_pile->adresse = new_maillon;
|
||||
}
|
||||
|
||||
char pop(pile** p_pile){
|
||||
char valeur= (p_pile->adresse)->valeur;
|
||||
pile* p_suivant=(*p_pile)->suivant;
|
||||
free(*p_pile);
|
||||
*p_pile=p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
char top(pile* p_pile){
|
||||
return p_pile->valeur;
|
||||
}
|
||||
|
||||
void clear(pile** p_pile){
|
||||
pile* p_suivant = *p_pile;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = (*p_pile)->suivant;
|
||||
free(*p_pile);
|
||||
*p_pile = p_suivant;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
pile* p_pile=NULL;
|
||||
printf("\n----------instruction----------\n1<char>- push\n2- pop\n3- top\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",pop(&p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",top(p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_pile);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
16
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_chainees.h~
Normal file
16
DEV/DEV1.1_suite/TP_Piles/Parenthèse/Pile_chainees.h~
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef PILE_CHAINEES_H
|
||||
#define PILE_CHAINEES_H
|
||||
|
||||
typedef struct pile{
|
||||
char valeur;
|
||||
struct pile* suivant;
|
||||
} pile;
|
||||
|
||||
void creerPile(pile** p_pile);
|
||||
int empty(pile* p_liste);
|
||||
void push(pile** p_pile, char new_valeur);
|
||||
char pop(pile** p_pile);
|
||||
char top(pile* p_pile);
|
||||
void clear(pile** p_pile);
|
||||
|
||||
#endif
|
83
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.c
Normal file
83
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct pile{
|
||||
maillon* adresse;
|
||||
}pile;
|
||||
|
||||
void creerPile(pile* p_pile){
|
||||
p_pile->adresse=NULL;
|
||||
}
|
||||
|
||||
int empty(pile p_pile){
|
||||
if (p_pile.adresse){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(pile* p_pile, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = p_pile->adresse;
|
||||
p_pile->adresse = new_maillon;
|
||||
}
|
||||
|
||||
char pop(pile* p_pile){
|
||||
char valeur= (p_pile->adresse)->valeur;
|
||||
maillon* p_suivant=(p_pile->adresse)->suivant;
|
||||
free(p_pile->adresse);
|
||||
p_pile->adresse=p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
char top(pile p_pile){
|
||||
return (p_pile.adresse)->valeur;
|
||||
}
|
||||
|
||||
void clear(pile* p_pile){
|
||||
maillon* p_suivant = p_pile->adresse;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = (p_pile->adresse)->suivant;
|
||||
free(p_pile->adresse);
|
||||
p_pile->adresse = p_suivant;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
pile p_pile;
|
||||
creerPile(&p_pile);
|
||||
printf("\n----------instruction----------\n1<char>- push\n2- pop\n3- top\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",pop(&p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",top(p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_pile);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
20
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.h
Normal file
20
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef CHAINE_H
|
||||
#define CHAINE_H
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct pile{
|
||||
maillon* adresse;
|
||||
}pile;
|
||||
|
||||
void creerPile(pile* p_pile);
|
||||
int empty(pile p_liste);
|
||||
void push(pile* p_pile, char new_valeur);
|
||||
char pop(pile* p_pile);
|
||||
char top(pile p_pile);
|
||||
void clear(pile* p_pile);
|
||||
|
||||
#endif
|
20
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.h~
Normal file
20
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.h~
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef PILE_CHAINEES_H
|
||||
#define PILE_CHAINEES_H
|
||||
|
||||
typedef struct maillon{
|
||||
char valeur;
|
||||
struct maillon* suivant;
|
||||
} maillon;
|
||||
|
||||
typedef struct pile{
|
||||
maillon* adresse;
|
||||
}pile;
|
||||
|
||||
void creerPile(pile* p_pile);
|
||||
int empty(pile p_liste);
|
||||
void push(pile* p_pile, char new_valeur);
|
||||
char pop(pile* p_pile);
|
||||
char top(pile p_pile);
|
||||
void clear(pile* p_pile);
|
||||
|
||||
#endif
|
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.o
Normal file
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/chaine.o
Normal file
Binary file not shown.
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/exe
Executable file
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/exe
Executable file
Binary file not shown.
62
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.c
Normal file
62
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include"tableau.h"
|
||||
//#include"chaine.h"
|
||||
|
||||
char parenthese(char symbole){
|
||||
if (symbole==')'){
|
||||
return '(';
|
||||
}
|
||||
if (symbole=='}'){
|
||||
return '{';
|
||||
}
|
||||
if (symbole==']'){
|
||||
return '[';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int numFichier;
|
||||
FILE* fichier;
|
||||
char caractere[2];
|
||||
pile p_pile;
|
||||
creerPile(&p_pile);
|
||||
|
||||
if (argc==1){
|
||||
fprintf(stderr,"Utilisation : \n%s <fichier>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
for (numFichier=1; numFichier<argc; numFichier++){
|
||||
fichier = fopen(argv[numFichier],"r");
|
||||
if (fichier==NULL){
|
||||
fprintf(stderr,"Erreur : Impossible d'ouvrir le fichier \"%s\" en écriture\n",argv[numFichier]);
|
||||
return 1;
|
||||
}
|
||||
while (fread(caractere,sizeof(char),1,fichier)){
|
||||
if (caractere[0]=='(' || caractere[0]=='{' || caractere[0]=='['){
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
if (caractere[0]==')' || caractere[0]=='}' || caractere[0]==']'){
|
||||
if (empty(p_pile)){
|
||||
if (top(p_pile)==parenthese(caractere[0])){
|
||||
pop(&p_pile);
|
||||
}
|
||||
else{
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty(p_pile)){
|
||||
printf("%s incorrect\n", argv[numFichier]);
|
||||
clear(&p_pile);
|
||||
}
|
||||
else{
|
||||
printf("%s correct\n", argv[numFichier]);
|
||||
}
|
||||
}
|
||||
}
|
62
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.c~
Normal file
62
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.c~
Normal file
@@ -0,0 +1,62 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
//#include"tableau.h"
|
||||
#include"chaine.h"
|
||||
|
||||
char parenthese(char symbole){
|
||||
if (symbole==')'){
|
||||
return '(';
|
||||
}
|
||||
if (symbole=='}'){
|
||||
return '{';
|
||||
}
|
||||
if (symbole==']'){
|
||||
return '[';
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int numFichier;
|
||||
FILE* fichier;
|
||||
char caractere[2];
|
||||
pile p_pile;
|
||||
creerPile(&p_pile);
|
||||
|
||||
if (argc==1){
|
||||
fprintf(stderr,"Utilisation : \n%s <fichier>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
for (numFichier=1; numFichier<argc; numFichier++){
|
||||
fichier = fopen(argv[numFichier],"r");
|
||||
if (fichier==NULL){
|
||||
fprintf(stderr,"Erreur : Impossible d'ouvrir le fichier \"%s\" en écriture\n",argv[numFichier]);
|
||||
return 1;
|
||||
}
|
||||
while (fread(caractere,sizeof(char),1,fichier)){
|
||||
if (caractere[0]=='(' || caractere[0]=='{' || caractere[0]=='['){
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
if (caractere[0]==')' || caractere[0]=='}' || caractere[0]==']'){
|
||||
if (empty(p_pile)){
|
||||
if (top(p_pile)==parenthese(caractere[0])){
|
||||
pop(&p_pile);
|
||||
}
|
||||
else{
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
push(&p_pile,caractere[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty(p_pile)){
|
||||
printf("%s incorrect\n", argv[numFichier]);
|
||||
clear(&p_pile);
|
||||
}
|
||||
else{
|
||||
printf("%s correct\n", argv[numFichier]);
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.o
Normal file
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/main.o
Normal file
Binary file not shown.
77
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.c
Normal file
77
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct pile{
|
||||
char* adresse;
|
||||
int taille;
|
||||
int capacite;
|
||||
} pile;
|
||||
|
||||
void creerPile(pile* p_pile){
|
||||
p_pile->capacite = 512;
|
||||
p_pile->taille = 0;
|
||||
p_pile->adresse = (char*) malloc(p_pile->capacite*sizeof(char));
|
||||
}
|
||||
|
||||
int empty(pile p_pile){
|
||||
if (p_pile.taille>0){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(pile* p_pile, char newValeur){
|
||||
if (p_pile->taille == p_pile->capacite){
|
||||
p_pile->capacite *= 2;
|
||||
p_pile->adresse = realloc(p_pile->adresse,p_pile->capacite*sizeof(char));
|
||||
}
|
||||
p_pile->adresse[p_pile->taille] = newValeur;
|
||||
p_pile->taille ++;
|
||||
}
|
||||
|
||||
char pop(pile* p_pile){
|
||||
p_pile->taille --;
|
||||
return p_pile->adresse[p_pile->taille];
|
||||
}
|
||||
|
||||
char top(pile p_pile){
|
||||
return p_pile.adresse[p_pile.taille-1];
|
||||
}
|
||||
|
||||
void clear(pile* p_pile){
|
||||
p_pile->taille=0;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
pile p_pile;
|
||||
creerPile(&p_pile);
|
||||
printf("\n----------instruction----------\n1<char>- push\n2- pop\n3- top\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",pop(&p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",top(p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_pile);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
free(p_pile.adresse);
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
17
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.h
Normal file
17
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef PILE_TABLEAU_H
|
||||
#define PILE_TABLEAU_H
|
||||
|
||||
typedef struct pile{
|
||||
char* adresse;
|
||||
int taille;
|
||||
int capacite;
|
||||
} pile;
|
||||
|
||||
void creerPile(pile* p_pile);
|
||||
int empty(pile p_pile);
|
||||
void push(pile* p_pile, char newValeur);
|
||||
char pop(pile* p_pile);
|
||||
char top(pile p_pile);
|
||||
void clear(pile* p_pile);
|
||||
|
||||
#endif
|
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.o
Normal file
BIN
DEV/DEV1.1_suite/TP_Piles/Parenthèse/tableau.o
Normal file
Binary file not shown.
4
DEV/DEV1.1_suite/TP_Piles/Parenthèse/test.txt
Normal file
4
DEV/DEV1.1_suite/TP_Piles/Parenthèse/test.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
({[
|
||||
]()
|
||||
}({
|
||||
}))
|
72
DEV/DEV1.1_suite/TP_Piles/Pile_chainees.c~
Normal file
72
DEV/DEV1.1_suite/TP_Piles/Pile_chainees.c~
Normal file
@@ -0,0 +1,72 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct m{
|
||||
char valeur;
|
||||
struct m* suivant;
|
||||
} maillon;
|
||||
|
||||
int empty(maillon* p_liste){
|
||||
if (p_liste){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(maillon** p_pile, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = *p_pile;
|
||||
*p_pile = new_maillon;
|
||||
}
|
||||
|
||||
char pop(maillon** p_pile){
|
||||
char valeur= (*p_pile)->valeur;
|
||||
maillon* p_suivant=(*p_pile)->suivant;
|
||||
free(*p_pile);
|
||||
*p_pile=p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
char top(maillon* p_pile){
|
||||
return p_pile->valeur;
|
||||
}
|
||||
|
||||
void clear(maillon** p_pile){
|
||||
maillon* p_suivant = *p_pile;
|
||||
while(p_suivant!=NULL){
|
||||
p_suivant = (*p_pile)->suivant;
|
||||
free(*p_pile);
|
||||
*p_pile = p_suivant;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
maillon* p_pile=NULL;
|
||||
printf("\n----------instruction----------\n1<char>- push\n2- pop\n3- top\n4- clear\n5- quit\n----------------------------------\n");
|
||||
while(choix!=5){
|
||||
printf("choix : ");
|
||||
scanf("%d%c",&choix,&caractere);
|
||||
if (choix==1){
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",pop(&p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==3){
|
||||
if (empty(p_pile)){
|
||||
printf("resultat : %c\n",top(p_pile));
|
||||
}
|
||||
}
|
||||
if (choix==4){
|
||||
clear(&p_pile);
|
||||
printf("La liste à bien été vidé\n");
|
||||
}
|
||||
}
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
0
DEV/DEV1.1_suite/TP_Piles/Pile_chainees.h~
Normal file
0
DEV/DEV1.1_suite/TP_Piles/Pile_chainees.h~
Normal file
54
DEV/DEV1.1_suite/TP_Piles/Q1_Chainees.c~
Normal file
54
DEV/DEV1.1_suite/TP_Piles/Q1_Chainees.c~
Normal file
@@ -0,0 +1,54 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct m{
|
||||
char valeur;
|
||||
struct m* suivant;
|
||||
} maillon;
|
||||
|
||||
int empty(maillon* p_liste){
|
||||
if (p_liste){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void push(maillon** p_pile, char new_valeur){
|
||||
maillon* new_maillon = (maillon*) malloc(sizeof(maillon));
|
||||
new_maillon->valeur = new_valeur;
|
||||
new_maillon->suivant = *p_pile;
|
||||
*p_pile = new_maillon;
|
||||
}
|
||||
|
||||
char pop(maillon** p_pile){
|
||||
char valeur= (*p_pile)->valeur;
|
||||
maillon* p_suivant=(*p_pile)->suivant;
|
||||
free(*p_pile);
|
||||
*p_pile=p_suivant;
|
||||
return valeur;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int choix=99;
|
||||
char caractere;
|
||||
maillon* p_pile=NULL;
|
||||
while(choix!=3){
|
||||
printf("1- nouvelle valeur 2- récupérer 3-quitter\n");
|
||||
printf("choix : ");
|
||||
scanf("%d",&choix);
|
||||
//printf("%d\n",choix);
|
||||
if (choix==1){
|
||||
printf("valeur : ");
|
||||
scanf(" %c",&caractere);
|
||||
push(&p_pile,caractere);
|
||||
}
|
||||
if (choix==2){
|
||||
if (empty(p_pile)){
|
||||
caractere = pop(&p_pile);
|
||||
printf("resultat : %c\n",caractere);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("O revoir BG\n");
|
||||
return 0;
|
||||
}
|
54
DEV/DEV1.1_suite/TP_Piles/Q3_Parentheses.c~
Normal file
54
DEV/DEV1.1_suite/TP_Piles/Q3_Parentheses.c~
Normal file
@@ -0,0 +1,54 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include"Pile_chainees.h"
|
||||
|
||||
char parenthese(char symbole){
|
||||
if (symbole==')'){
|
||||
return '('
|
||||
}
|
||||
if (symbole=='}'){
|
||||
return '{'
|
||||
}
|
||||
if (symbole==']'){
|
||||
return '['
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int numFichier;
|
||||
FILE* fichier;
|
||||
char caractere[2];
|
||||
maillon* p_pile=NULL;
|
||||
|
||||
if (argc==1){
|
||||
fprintf(stderr,"Utilisation : \n%s <fichier>",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
for (numFichier=1; numFichier<argc; numFichier++){
|
||||
fichier = fopen(argv[numFichier],"r");
|
||||
if (fichier==NULL){
|
||||
fprintf(stderr,"Erreur : Impossible d'ouvrir le fichier \"%s\" en écriture",argv[numFichier]);
|
||||
return 1;
|
||||
}
|
||||
while (fread(caractere,sizeof(char),1,fichier)){
|
||||
if (caractere[0]=='(' || caractere[0]=='{' caractere[0]=='['){
|
||||
push(p_pile,caractere[0]);
|
||||
}
|
||||
if (caractere[0]==')' || caractere[0]=='}' caractere[0]==']'){
|
||||
if (top(p_pile)==parenthese(caractere[0])){
|
||||
pop(&p_pile);
|
||||
}
|
||||
else{
|
||||
push(p_pile,caractere[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p_pile==NULL){
|
||||
printf("%s correct\n");
|
||||
}
|
||||
else{
|
||||
printf("%s incorrect");
|
||||
}
|
||||
}
|
||||
}
|
1
DEV/DEV1.1_suite/TP_Piles/Q_Chainees.c~
Normal file
1
DEV/DEV1.1_suite/TP_Piles/Q_Chainees.c~
Normal file
@@ -0,0 +1 @@
|
||||
#include
|
0
DEV/DEV1.1_suite/TP_Piles/Q_Chaineesc~
Normal file
0
DEV/DEV1.1_suite/TP_Piles/Q_Chaineesc~
Normal file
0
DEV/DEV1.1_suite/TP_Piles/test.txt~
Normal file
0
DEV/DEV1.1_suite/TP_Piles/test.txt~
Normal file
Reference in New Issue
Block a user