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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define CLEAR system("cls")
typedef struct Element Element;
struct Element
{
int entier;
Element *suivant;
Element *precedent;
};
typedef struct
{
Element *premier;
Element *deriner;
}Liste;
void header();
void menu(Liste *lista);
void insertionn(Liste *lista, int var);
void affichage(Liste *lista);
void read_kb(Liste *list);
Liste *initialisation();
int main()
{
CLEAR;
header();
Liste *lista = initialisation();
menu(lista);
return 0;
}
Liste *initialisation()
{
Element *element = malloc(sizeof(*element));
Liste *liste = malloc(sizeof(*liste));
if(element == NULL || liste == NULL)
{
printf("\n\t Une erreur s'est produite lors de la création de la chaine \n");
exit(EXIT_FAILURE);
}
element->suivant = NULL;
element->precedent = NULL;
liste->premier = element;
return liste;
}
void read_kb(Liste *listaa)
{
CLEAR;
header();
int active=1,entier,tmp;
while(active)
{
printf("\n\n\t\t Donner un entier : ");
scanf("%d",&entier);
insertionn(listaa,entier);
//repeat:
printf("\n\t\t Vous-voulez continuer [1.Oui] [0.Non] ");
tmp = getch() - 48;
switch(tmp)
{
case 0:
active = 0;
break;
case 1:
active = 1;
break;
default:
printf("\n\t Aucune valeur correspand a votre choix ");
//goto repeat;
}
}
}
void affichage(Liste *lista)
{
printf("ossel hna");
if(lista == NULL)
{
printf("mawssel walou");
exit(EXIT_FAILURE);
}
Element *actuel = lista->premier;
if(actuel == NULL)
{
printf("\n\t Une erreur s'est produite lors l'appelle de la fonction affichage() \n");
}
while(actuel->suivant != NULL)
{
printf(" +----+ ");
printf(" | %-2d | ",actuel->entier);
printf(" +----+ ");
actuel = actuel->suivant;
}
system("pause");
}
void insertionn(Liste *lista, int var)
{
Element *new_element = malloc(sizeof(*new_element));
Element *old_element = malloc(sizeof(*old_element));
if (new_element == NULL || old_element == NULL)
{
printf("\n\t Une erreur s'est produite lors de l'ajout d'un nouveau element \n");
exit(EXIT_FAILURE);
}
old_element = lista->premier;
old_element->precedent = new_element;
new_element->entier = var;
new_element->precedent = NULL;
new_element->suivant = lista->premier;
lista->premier = new_element;
}
void header()
{
int i;
printf("\n\t %c",201);
for(i=0;i<=50;i++){printf("%c",205);}
printf("%c",187);
printf("\n\t %c \t\t LPI S4 \t 2012/2013 \t\t%c",186,186);
printf("\n\t %c \t Par : Anas Benzalim && Fouad Jadouani \t%c",186,186);
printf("\n\t %c",204);
for(i=0;i<=50;i++){printf("%c",205);}
printf("%c",185);
printf("\n\t %c \t\t TP N3 : Exercice 3\t\t\t%c",186,186);
printf("\n\t %c",200);
for(i=0;i<=50;i++){printf("%c",205);}
printf("%c",188);
printf("\n");
}
void menu(Liste *lista)
{
int choix;
printf("\t\t\t +-----+------------------+ \n");
printf("\t\t\t | 1 | Afficher | \n");
printf("\t\t\t +-----+------------------+ \n");
printf("\t\t\t | 2 | Inserer | \n");
printf("\t\t\t +-----+------------------+ \n");
printf("\t\t\t | 3 | Supprimer | \n");
printf("\t\t\t +-----+------------------+ \n");
printf("\t\t\t | 4 | Chercher | \n");
printf("\t\t\t +-----+------------------+ \n");
repeat:
printf("\n\t\t\t Entrer votre choix : ");
choix = getch() - 48;
switch(choix)
{
case 1:
affichage(lista);
main();
break;
case 2:
read_kb(lista);
main();
break;
case 3:
//suppression(lista);
main();
break;
case 4:
//chercher(lista);
main();
break;
default:
printf("\n\t\t\t Aucune valeur correspand a votre choix ");
goto repeat;
}
} |
Partager