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
|
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
typedef struct Trans{
char mot[20];
char traduction[20];
struct Trans*suiv;
struct Trans*prec;
}T;
/**************************/
/* Affichage */
/**************************/
void Affichage(T* courant){
if(courant != NULL){
cout<<courant->mot ;
cout<<" --------> ";
cout<<courant->traduction<<endl;
Affichage(courant->suiv);
}
}
/**************************/
/* Ajouter */
/**************************/
T* InsertDeb(T* courant){
T* nouveau = new T;
char rep;
cout<<"\n Donner un mot: ";
cin>>nouveau->mot;
cout<<"\n Donner sa traduction: ";
cin>>nouveau->traduction;
nouveau->suiv = courant;
nouveau->prec = NULL;
courant = nouveau;
return courant;
}
/**************************/
/* Recherche */
/**************************/
void Rechercher(T* tete , char w[20]){
T* courant = tete;
do{
if( strcmp(courant->mot , w) == 0){
cout<<courant->mot<<" ------> "<<courant->traduction;
}else{
cout<<"?"<<endl;
}
courant = courant->suiv;
}while(courant != NULL);
}
/**************************/
/* Supprimer */
/**************************/
void Supprimer(T* tete , char w[20]){
T* courant = tete;
if(courant == NULL){
cout<<"Liste Vide!" ;
}else
if(strcmp(courant->mot , w) == 0){
if( courant->prec == NULL){
(courant->suiv)->prec = NULL;
tete = courant->suiv;
}else if(courant->suiv == NULL){
(courant->prec)->suiv = NULL;
}else{
(courant->prec)->suiv = (courant->suiv)->prec;
(courant->suiv)->prec = (courant->prec)->suiv;
}
delete courant;
}else{
Supprimer(courant->suiv , w);
}
}
/**************************/
/* Main */
/**************************/
int main(){
T* tete;
T* queue = tete;
int choix;
char word[20] , rep1 , rep2;
do{
cout<<"========= MENU ========"<<endl;
cout<<"Ajouter un mot (1)"<<endl;
cout<<"Affichage des mots (2)"<<endl;
cout<<"Supprimer un mot (3)"<<endl;
cout<<"Rechercher un mot (4)"<<endl;
cout<<"======================="<<endl;
cout<<"\n\n **********Enter un choix: **********\n";
cin>>choix;
switch(choix){
case 1:
do{
tete = InsertDeb(tete);
cout<<"\n ====Autre insertion (o/n) ?====\n"<<endl;
cin>>rep1;
}while(rep1=='o');
break;
case 2:
Affichage(tete);
break;
case 3:
cout<<"Donner le mot a supprimer: ";
cin>>word;
Supprimer(tete , word);
break;
case 4:
cout<<"Donner le mot a rechercher: ";
cin>>word;
Rechercher(tete , word);
default:
cout<<"Erreur de saisie"<<endl;
break;
}
cout<<"\n\n"<<endl;
cout<<"\n\n **********Autre choix (o/n)?********** \n";
cin>>rep2;
}while(rep2 == 'o');
getch();
return 0;
} |
Partager