liste chainee
This commit is contained in:
parent
3fa8a008e9
commit
4144375bae
@ -10,14 +10,20 @@ int main(int argc, char const *argv[])
|
||||
int x;
|
||||
int y;
|
||||
couleur c;
|
||||
|
||||
fread(&x,sizeof(int),1,f);
|
||||
fread(&y,sizeof(int),1,f);
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,x,y);
|
||||
|
||||
fseek(f,(sizeof(unsigned long int)*768*(1024/2)),SEEK_SET);
|
||||
|
||||
for(int i=1024/2;i<x;i++)
|
||||
{
|
||||
|
||||
fseek(f,(sizeof(unsigned long int)*(768/2)),SEEK_CUR);
|
||||
|
||||
for(int j=768/2;j<y;j++)
|
||||
{
|
||||
fread(&c,sizeof(unsigned long int),1,f);
|
||||
|
132
DEV1.1/TP14/listchainee.c
Normal file
132
DEV1.1/TP14/listchainee.c
Normal file
@ -0,0 +1,132 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
struct mail {
|
||||
unsigned short int valeur;
|
||||
struct mail* suivant;
|
||||
};
|
||||
|
||||
typedef struct mail maillon;
|
||||
|
||||
void afficher(maillon* premier)
|
||||
{
|
||||
maillon* p;
|
||||
for(p = premier; p != NULL; p = p->suivant)
|
||||
{
|
||||
printf("%d ", p->valeur);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
maillon* ajouter_debut(maillon* premier,unsigned short int nouveau)
|
||||
{
|
||||
maillon* p = (maillon*) malloc(sizeof(maillon));
|
||||
if (p)
|
||||
{
|
||||
p->suivant = premier;
|
||||
p->valeur = nouveau;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
maillon* ajouter_dernier(maillon* premier,unsigned short int chiffre)
|
||||
{
|
||||
maillon* nouveau = (maillon*) malloc(sizeof(maillon));
|
||||
nouveau -> suivant = NULL;
|
||||
nouveau ->valeur = chiffre;
|
||||
maillon* p = (maillon*) malloc(sizeof(maillon));
|
||||
for(p = premier; p != NULL; p = p->suivant)
|
||||
{
|
||||
if(p->suivant==NULL)
|
||||
{
|
||||
p->suivant=nouveau;
|
||||
return premier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned short int retirer_premier(maillon* premier)
|
||||
{
|
||||
maillon* postp = (maillon*) malloc(sizeof(maillon));
|
||||
postp = premier -> suivant;
|
||||
unsigned short int chiffre = premier -> valeur;
|
||||
free(premier);
|
||||
return chiffre;
|
||||
}
|
||||
|
||||
unsigned short int retirer_dernier(maillon* premier)
|
||||
{
|
||||
maillon* p = (maillon*) malloc(sizeof(maillon));
|
||||
maillon* anteP = (maillon*) malloc(sizeof(maillon));
|
||||
for(p = premier; p != NULL; p = p->suivant)
|
||||
{
|
||||
if(p->suivant==NULL)
|
||||
{
|
||||
anteP ->suivant=NULL;
|
||||
free(p);
|
||||
return p->valeur;
|
||||
}
|
||||
else
|
||||
{
|
||||
anteP = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
maillon* circuler(maillon* premier)
|
||||
{
|
||||
premier= ajouter_debut(premier,retirer_dernier(premier));
|
||||
return premier;
|
||||
}
|
||||
|
||||
maillon* circulerAnti(maillon* premier)
|
||||
{
|
||||
premier=ajouter_dernier(premier,retirer_premier(premier));
|
||||
return premier;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
srand(time(NULL));
|
||||
unsigned short int number = (rand() % (999 - 111 + 1)) + 111;
|
||||
maillon *mail = malloc(sizeof(maillon));
|
||||
mail -> valeur = number;
|
||||
mail -> suivant = NULL;
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
number = (rand() % (999 - 111 + 1)) + 111;
|
||||
mail = ajouter_debut(mail,number);
|
||||
}
|
||||
afficher(mail);
|
||||
|
||||
int max = mail -> valeur;
|
||||
for(maillon* p = mail; p != NULL; p = p->suivant)
|
||||
{
|
||||
if (p->valeur>max)
|
||||
{
|
||||
max = p->valeur;
|
||||
}
|
||||
}
|
||||
printf("le max est: %d \n", max);
|
||||
printf("la liste sans le dernier nombre:");
|
||||
retirer_dernier(mail);
|
||||
afficher(mail);
|
||||
printf("la liste cyclé: ");
|
||||
mail=circuler(mail);
|
||||
afficher(mail);
|
||||
printf("ajout de 666 à la fin : ");
|
||||
mail=ajouter_dernier(mail,666);
|
||||
afficher(mail);
|
||||
printf("suppresion du premier element: \n");
|
||||
retirer_premier(mail);
|
||||
afficher(mail);
|
||||
/*printf("cycle mais dans lautre sens:\n");
|
||||
mail=circulerAnti(mail);
|
||||
afficher(mail);*/
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
46
DEV1.1/random/listchainee.c
Normal file
46
DEV1.1/random/listchainee.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct maillon
|
||||
{
|
||||
char lettre;
|
||||
struct maillon* suiv;
|
||||
};
|
||||
|
||||
typedef struct maillon maillon;
|
||||
|
||||
int estVide(maillon *chaine)
|
||||
{
|
||||
return(chaine == NULL);
|
||||
}
|
||||
|
||||
void afficher(maillon *chaine)
|
||||
{
|
||||
maillon *lecture=chaine;
|
||||
while(!estVide(lecture))
|
||||
{
|
||||
printf("%c", lecture->lettre);
|
||||
lecture=lecture->suiv;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
maillon* ajouterDebut(maillon *m,char c)
|
||||
{
|
||||
maillon *p = malloc(sizeof(maillon));
|
||||
p -> lettre=c;
|
||||
p -> suiv = m;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
maillon *chaine=malloc(sizeof(maillon));
|
||||
chaine->lettre='t';
|
||||
chaine = ajouterDebut(chaine,'s');
|
||||
chaine = ajouterDebut(chaine,'e');
|
||||
chaine = ajouterDebut(chaine,'t');
|
||||
afficher(chaine);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user