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

m

parent 1009967b
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(l1->s == NULL){
free(l1);
return listenouv();
}
else{
l = l->s ;
free(l1);
return l ;
}
}
Nat lng(Liste l){
return (l->s == NULL) ? 1 : 1 + lng(l);
}
bool vide(Liste l){
return (lng(l) == 0) ;
}
bool app(Liste l, S x){
if(l == NULL){
return false ;
}
else{
if(l->v == x ){
return true ;
}
else{
Liste l1 = l ;
app(supt(l1), x);
free(l1);
}
}
}
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{
chg1(supt(l) ,x ,y);
}
}
}
Liste sup1(Liste l , S x){
if( l== NULL){
return NULL ;
}
else{
if(l->s->v == x ){
l->s = l->s->s ;
return l ;
}
else{
sup1(supt(l), 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 ;
}
}
#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 );
#endif
\ No newline at end of file
File added
// 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
File added
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();
for(int i = 0 ; i< 5 ; i++){
l = ajout(l , i);
printf("%d\n",tete(l) );
}
for(int i = 5 ; i< 10 ; i++){
l = adjq(l , i);
printf("%d\n",queue(l) );
}
//printf("%d\n",tete(l) );
for(int i = 5 ; i< 10 ; i++){
l = supt(l);
printf("%d\n",tete(l) );
}
return 0;
}
\ No newline at end of file
File added
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