Skip to content
Snippets Groups Projects
Commit d6f42bfb authored by DARWICH ALI's avatar DARWICH ALI
Browse files

m

parent 467235c6
Branches
No related merge requests found
#include "ListeSimple.h"
Liste listenouv(){
return NULL;
}
Liste ajout(Liste l, S x){
Liste l1 = MALLOC(Strliste) ;
l1->v = x ;
if(l == NULL){
return l1 ;
}
else{
l1->s = l;
return l1;
}
}
S tete(Liste l){
return l->v ;
}
Liste supt(Liste l ){
Liste l1 = l;
if(l == NULL){
return listenouv();
}
else{
l = l->s ;
free(l1);
return l ;
}
}
Nat lng(Liste l){
return (l == NULL) ? 0 : 1 + lng(l->s);
}
bool vide(Liste l){
return (lng(l) == 0) ;
}
bool app(Liste l, S x){
if(l == NULL){
//printf("false ?\n");
return false ;
}
else{
//printf("else\n");
if(l->v == x ){
return true ;
}
else{
Liste l1 = l ;
app(supt(l1), x);
}
}
}
Liste rech1(Liste l, S x){
if(l == NULL){
return l ;
}
else{
if(l->v == x){
return l ;
}
else{
rech1(supt(l), x);
}
}
}
Liste chg1(Liste l , S x , S y){
if(l == NULL){
return NULL ;
}
else{
if(l->v == x){
l->v = y ;
return l ;
}
else{
Liste l1 = l;
ajout(chg1(supt(l1), x ,y),l1->v);
}
}
}
Liste sup1(Liste l , S x){
Liste l1 = l ;
if(l== NULL){
return NULL ;
}
else{
if(l->v == x ){
l = l->s;
return l1->s ;
}
else{
sup1(l1->s, x);
}
}
}
S queue(Liste l){
while(l->s != NULL){
l = l->s ;
}
return l->v ;
}
Liste adjq(Liste l , S x){
Liste l1 = MALLOC(Strliste);
l1->v = x;
if(l == NULL){
return l1 ;
}
else{
Liste l2 = l;
while(l2->s != NULL){
l2 = l2->s ;
}
l2->s = l1 ;
return l ;
}
}
Liste supq(Liste l ){
if(l == NULL){
return listenouv() ;
}
else{
Liste l2 = l;
while(l2->s != NULL){
l2 = l2->s ;
}
l = l2 ;
return l ;
}
}
S ieme(Liste l , Nat x){
Liste l1 = l ;
for(int i = 0 ; i <(int) x ; i++){
l1 = l1->s ;
}
return l1->v ;
}
Liste inser(Liste l , Nat n , S x){
Liste l2 = MALLOC(Strliste);
l2->v = x ;
Liste l1 = l ;
if(l ==NULL){
return l2 ;
}
else{
for(int i = 0 ; i < (int)n -2 ; i++){
l1 = l1->s ;
}
l2->s = l1->s->s ;
l1->s = l2 ;
return l ;
}
}
Liste sup_ieme(Liste l , Nat n){
Liste l1 = l ;
if(l == NULL){
return l ;
}
else{
for(int i = 0 ; i<(int) n-1 ; i++){
l1 = l1->s ;
}
l1->s = l1->s->s ;
}
return l ;
}
#ifndef __LISTESIMPLE__
#define __LISTESIMPLE__
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "base.h"
#define S Nat
typedef struct strliste{
S v ;
struct strliste * s ;
} Strliste , *Liste ;
Liste listenouv();//
Liste ajout(Liste l, S x);//
S tete(Liste l) ;//
Liste supt(Liste l);//
Nat lng(Liste l);
bool vide(Liste l);
bool app(Liste l, S x);
Liste rech1(Liste l, S x) ;
Liste chg1(Liste l , S x , S y);
Liste sup1(Liste l , S x);
S queue(Liste l);
Liste adjq(Liste l , S x) ;
Liste supq(Liste l );
S ieme(Liste l , Nat x);
Liste inser(Liste l , Nat n , S x);
Liste sup_ieme(Liste l , Nat n);
#endif
\ No newline at end of file
File deleted
// fichier base.h
#ifndef BASE
#define BASE
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
typedef bool Bool;
#define faux false
#define vrai true
//#define vrai 1
//#define faux 0
//typedef unsigned char Bool;
typedef unsigned int Nat;
typedef int Ent;
typedef float Reel;
typedef float Rat;
typedef char Car;
typedef Car * Chaine;
#define MALLOC(type) ((type*)malloc(sizeof(type)))
#define MALLOCN(type, n) ((type*)calloc(n, sizeof(type)))
#define CALLOCN(type, n) ((type*)malloc(n * sizeof(type)))
#define REALLOC(t, type, n) ((type*)realloc(t, n * sizeof(type)))
#define FREE(t) free(t)
#endif
\ No newline at end of file
CC = gcc -g
CFLAGS = -W -Wall
SOURCES = $(wildcard *.c)
OBJETS = $(SOURCES:.c=.o)
EXEC = main
$(EXEC) : $(OBJETS)
$(CC) $(CFLAGS) -o $@ $^
%.o : %.c
$(CC) $(CFLAGS) -c $<
clean:
rm $(OBJETS)
/*
#include "ListeSimple.h"
int main(){
Liste l = listenouv();
//printf("vide ? : %d\n",vide(l));
//for(int i = 0 ; i <(int)lng(l) ; i++){l= l->s ; printf(" %d ",l->v) ;}
for(int i = 5 ; i > 0 ; i--){
l = ajout(l , i);
//printf("%d ",tete(l) );
}
//printf("\n");
/*
printf("longueur est : %d\n",lng(l));
*/
//for(int i = 0 ; i <(int)lng(l) ; i++){l= l->s ; printf(" %d ",l->v) ;}
/*for(int i = 5 ; i < 10 ; i++){
l = adjq(l , i);
//printf("%d\n",queue(l) );
}
*/
/*
Liste l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
printf("%d\n",tete(l) );
for(int i = 0 ; i < 5; i++){
l = supt(l);
//printf("%d ",tete(l) );
}
printf("\n");
//printf("tete: %d\n",tete(l));
printf("long :%d\n",lng(l) );
printf("vide ? : %d\n",vide(l));
printf("est ce que 5 app a l ? :%d\n",app(l , 0));
*/
/*
l = rech1(l , 2);
Liste l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
l = chg1(l , 1, 3);
printf("%d\n",lng(l));
l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
l = sup1(l , 2) ;
l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
*/
/*
for(int i = 5 ; i < 10 ; i++){
l = adjq(l , i);
//printf("%d\n",queue(l) );
}
Liste l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
printf("%d\n",queue(l));
l = supq(l);
l = supq(l);
*/
/*
Liste l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
printf("%d\n", ieme(l ,1)) ;
l = inser(l , 1 , 9);
l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
l = sup_ieme(l , 3) ;
l1 = l ;
for(int i = 0 ; i <(int)lng(l) ; i++){
printf("%d ",l1->v);
l1 = l1->s ;
}
printf("\n");
*/
/*
return 0;
}
*/
\ No newline at end of file
personne(alice, f, 85, paris, retraitée, 1500).
personne(édouard, m , 40, strasbourg, ingénieur, 3000).
personne(luc, m , 27, paris, enseignant, 1800).
personne(pauline, f, 35, marseille, informaticien, 2000).
individu(X) :- personne(X,_,_,_,_,_).
masculin(X) :- personne(X,m,_,_,_,_).
féminin(X) :- personne(X,f,_,_,_,_).
est_âgé_de(X,A) :- personne(X,_,A,_,_,_).
majeur(X):- personne(X,_,A,_,_,_), A > 18.
mineur(X):- personne(X,_,A,_,_,_), A < 18.
même_âge(X,Y):- personne(X,_,Z,_,_,_) ,personne(Y,_,H,_,_,_), Z =:= H.
habite_la_même_ville(X,Y):- personne(X,_,_,H,_,_) ,personne(Y,_,_,Z,_,_), Z = H.
époux_possibles(X,Y):- personne(X,_,_,_,_,_) ,personne(Y,_,_,_,_,_), majeur(X) , majeur(Y).
même_profession(X,Y):-personne(X,_,_,_,Z,_) ,personne(Y,_,_,_,H,_), Z = H.
gagne_plus_que(X,Y):- personne(X,_,_,_,_,Z) ,personne(Y,_,_,_,_,H), Z > H.
salaires_du_même_ordre(X,Y):- personne(X,_,_,_,_,Z) ,personne(Y,_,_,_,_,H), V = Z/H , V =< 1.2 , V >= 0.8 .
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment