1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct Etudiant{
char nom[10];
struct Etudiant *suivant;
}*debut=NULL;
void creer();
void ajoutdebut();
void affiche();
void ajoutfin();
void insereravant();
void insererapres();
void supp();
int main()
{
int n;
printf("tapper n\n");
scanf("%d",&n);
system("color 2A");
creer();
ajoutdebut();
ajoutdebut();
affiche();
insereravant();
insererapres();
affiche();
affiche();
supp(n);
return 0;
}
void creer()
{
struct Etudiant *etudiant=(struct Etudiant*)malloc(sizeof(struct Etudiant));
if(debut!=NULL)return;
printf("creation de la liste\n");
scanf("%s",etudiant->nom);
etudiant->suivant=NULL;
debut=etudiant;
}
void ajoutdebut()
{
struct Etudiant *etudiant=(struct Etudiant*)malloc(sizeof(struct Etudiant));
scanf("%s",etudiant->nom);
etudiant->suivant=debut;
debut=etudiant;
}
void affiche()
{
struct Etudiant *temp;
temp=debut;
while(temp!=NULL)
{
printf("%s->",temp->nom);
temp=temp->suivant;
}
printf("NULL\n");
}
void insereravant()
{
struct Etudiant *temp;
struct Etudiant *etudiant=(struct Etudiant*)malloc(sizeof(struct Etudiant));
scanf("%s",etudiant->nom);
temp=debut;
int cont=1;
int pos=1;
while(cont!=pos&&temp!=NULL)
{
temp=temp->suivant;
cont++;
}
etudiant->suivant=temp->suivant;
temp->suivant=etudiant;
}
void insererapres()
{
struct Etudiant *temp;
struct Etudiant *etudiant=(struct Etudiant*)malloc(sizeof(struct Etudiant));
scanf("%s",etudiant->nom);
temp=debut;
int cont=1;
int pos=3;
while(cont!=pos&&temp!=NULL)
{
temp=temp->suivant;
cont++;
}
etudiant->suivant=temp->suivant;
temp->suivant=etudiant;
}
void supp(int N)
{
struct Etudiant *temp;
struct Etudiant *etudiant=(struct Etudiant*)malloc(sizeof(struct Etudiant));
int cont,pos;
temp=debut;
cont=1;
pos=N;
while(cont!=pos-1&&temp!=NULL)
{
temp=temp->suivant;
cont++;
}
struct Etudiant *t;
t=temp->suivant;
temp->suivant=temp->suivant->suivant;
t->suivant=NULL;
temp=debut;
while(temp!=NULL)
{
printf("%s->",temp->nom);
temp=temp->suivant;
}
printf("NULL\n");
} |
Partager