Mono-neurone | Grand News : TotalRecall est un comique !!! ;-)
Ok ben si ca peut vous amuser ma fois voici mon ti code. C'est rien d'exceptionnel, on est bien d'accord mais ca a le mérite de fonctionner (enfin plus ou moins). Merci a tous ceux qui m'ont aider et "merci" a tous ceux que cela amuse...
Mes déclas
Code :
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <iostream.h>
- #include <ctype.h>
- #include <sstream>
-
- struct Page
- {
- int NumPg;
- struct Page * PtrNextPg;
- };
- struct Mot
- {
- char * ZoneMot;
- struct Page * PtrPremPg;
- struct Page * PtrDernPg;
- struct Mot * PtrNextMot;
- };
- typedef struct Mot TypeMot;
- typedef TypeMot * TypeMotPtr;
- typedef struct Page TypePage;
- typedef TypePage * TypePagePtr;
- TypeMotPtr PushMotNew ( TypeMotPtr );
- TypeMotPtr PushPopMotExist ( TypeMotPtr, int );
- TypeMotPtr PushPgWiz ( TypeMotPtr );
- TypeMotPtr PushPg ( TypeMotPtr );
- TypeMotPtr PopMot ( TypeMotPtr );
- TypeMotPtr PopPg ( TypeMotPtr );
- TypeMotPtr Mot0Pg ( TypeMotPtr, TypeMotPtr, TypeMotPtr );
- int GetChoix( void );
- int CinInt ( void );
- int MotIsEmpty ( TypeMotPtr );
- int PageIsEmpty ( TypePagePtr );
- void SortirPages ( TypeMotPtr );
- void SortirMots ( TypeMotPtr );
- void Affichage ( TypeMotPtr );
- void MenuPg ( void );
- void MenuPrp ( void );
- template <class TMP>
- int TestAlloc ( TMP Obj )
- {
- if (Obj == NULL)
- {//test d'allocation
- cout << endl << endl <<" Plus assez d'espace memoire pour memoriser quoi que ce soit !" << endl << endl;
- return 0;
- }
- else return 1;
- };
|
Mon main ...
Code :
- #include "decla.h"
- void main ( void )
- {
- TypeMotPtr MotPtr = NULL;
- int Choix;
- Choix = GetChoix();
- while ( Choix != 6 )
- {
- switch ( Choix )
- {
- case 1 :
- // entrée mots & pages
- MotPtr = PushMotNew ( MotPtr );
- break;
- case 2 :
- // entrée de pages d'un mot existant
- MotPtr = PushPopMotExist ( MotPtr, 1 );
- break;
- case 3 :
- // suppression d'un mot
- if ( !MotIsEmpty ( MotPtr ) )
- {
- MotPtr = PopMot ( MotPtr );
- }
- else
- {
- cout << endl << endl << "Il n y a plus de mot dans l index !!!" << endl << endl;
- }
- break;
- case 4 :
- // suppression d'une page
- MotPtr = PushPopMotExist ( MotPtr, 0);
- break;
- case 5 :
- // affichage de l'index et de l etat des listes chainées
- Affichage (MotPtr);
- break;
- case 6 :
- cout << endl <<" *** Fin du programme ***" <<endl<<endl<<endl;
- break;
- default:
- cout << endl << "Choix incorrecte !" << endl;
- break;
- }
- system("pause" );
- system("cls" );
- Choix = GetChoix();
- }
- }
- int MotIsEmpty ( TypeMotPtr TopPtrMot )
- {
- return (TopPtrMot == NULL ? 1 : 0);
- }
- int PageIsEmpty ( TypePagePtr TopPtrPg )
- {
- return (TopPtrPg == NULL ? 1 : 0);
- }
|
Mon Saisie.cpp
Code :
- #include "decla.h"
- int GetChoix()
- {
- int x;
- bool ok = false;
- MenuPrp ();
- while ( ok != true )
- {
- cout << endl << " Entrer votre choix :" << endl;
- if (cin >> x)// fait la saisie et verifie que ca c'est bien passé.
- ok = true;
- else
- {
- cout << endl << endl << "Veuillez entrer un entier svp !!!" << endl;
- system("pause" );
- system("cls" );
- MenuPrp ();
- cin.clear(); // efface les bits erronés
- }
- while(cin.get() != '\n'); // vire le reste de la ligne jusqu'à arriver a la fin
- }
- return x;
- }
- int CinInt ()
- {
- int Val;
- while ( ! (cin >> Val) )
- {
- cin.clear();
- cin.ignore ( sizeof (cin),'\n');
- cout << endl << "Vous devez saisir un entier !!!" << endl;
- cout << "Veuillez reintroduire celui-ci ..." << endl << flush;
- }
- return Val;
- }
|
mon FctsPP.cpp
Code :
- #include "decla.h"
- using namespace std;
- TypeMotPtr PushMotNew ( TypeMotPtr TopPtrMot )
- {
- int Choix = 0;
- int FlagPass = 1;
- char * LeMot;
- LeMot = new ( char );
- if (! TestAlloc ( LeMot )) return 0;
- TypeMotPtr NewPtrMot;
- TypeMotPtr PrecPtrMot;
- TypeMotPtr CurrentPtrMot;
- CurrentPtrMot = TopPtrMot;
- PrecPtrMot = TopPtrMot;
- cout << "Entrez le mot dans l'index." << endl;
- cin >> LeMot;
- if ( TopPtrMot == NULL )
- {//insert du premier mot
- NewPtrMot = new (TypeMot);
- if (! TestAlloc ( NewPtrMot )) return 0;
- NewPtrMot -> PtrNextMot = TopPtrMot;
- NewPtrMot -> ZoneMot = LeMot;
- NewPtrMot -> PtrPremPg = NULL;
- NewPtrMot -> PtrDernPg = NULL;
- TopPtrMot = NewPtrMot;
- CurrentPtrMot = TopPtrMot;
- }
- else
- {
- while (( CurrentPtrMot != NULL ) && ( strcmp ( CurrentPtrMot -> ZoneMot , LeMot ) < 0 ))
- {
- PrecPtrMot = CurrentPtrMot;
- CurrentPtrMot = CurrentPtrMot -> PtrNextMot;
- }
- if ( CurrentPtrMot != NULL )
- {
- if (strcmp ( CurrentPtrMot -> ZoneMot , LeMot) != 0)
- {// si le mot n'est pas encore repris dans l'index
- NewPtrMot = new (TypeMot);
- if (! TestAlloc ( NewPtrMot )) return 0;
- NewPtrMot -> PtrNextMot = CurrentPtrMot;
- NewPtrMot -> ZoneMot = LeMot;
- NewPtrMot -> PtrPremPg = NULL;
- NewPtrMot -> PtrDernPg = NULL;
- if ( CurrentPtrMot == TopPtrMot )
- {//insert en début
- TopPtrMot = NewPtrMot;
- }
- else
- {//insert en milieu
- PrecPtrMot -> PtrNextMot = NewPtrMot;
- }
- CurrentPtrMot = NewPtrMot;
- }
- else
- {
- cout <<endl<<" Ce mot est deja repris dans l index !"<<endl<<endl;
- FlagPass = 0;
- }
- }
- else
- {// insert en fin
- NewPtrMot = new (TypeMot);
- if (! TestAlloc ( NewPtrMot )) return 0;
- NewPtrMot -> PtrNextMot = CurrentPtrMot;
- NewPtrMot -> ZoneMot = LeMot;
- NewPtrMot -> PtrPremPg = NULL;
- NewPtrMot -> PtrDernPg = NULL;
- PrecPtrMot -> PtrNextMot = NewPtrMot;
- CurrentPtrMot = NewPtrMot;
- }
- }
- if ( FlagPass == 1)
- {
- CurrentPtrMot = PushPgWiz ( CurrentPtrMot );
- TopPtrMot = Mot0Pg ( PrecPtrMot, TopPtrMot, CurrentPtrMot );
- }
- return TopPtrMot;
- }
- TypeMotPtr PushPopMotExist ( TypeMotPtr TopPtrMot, int PushOrPop )
- {
- // PushOrPop == 1 si Push
- // PushOrPop == 0 si Pop
- char * MotATrouv;
- MotATrouv = new ( char );
- if (! TestAlloc ( MotATrouv )) return 0;
- char * MsgVerb;
- TypeMotPtr PrecPtrMot;
- TypeMotPtr CurrentPtrMot;
- CurrentPtrMot = TopPtrMot;
- PrecPtrMot = TopPtrMot;
- if ( CurrentPtrMot != NULL )
- {
- SortirMots ( TopPtrMot );
- if ( PushOrPop == 1 )
- {
- MsgVerb = "ajouter";
- }
- else
- {
- MsgVerb = "suprimer";
- }
- cout << endl << " Pour lequel de ces mots desirez vous " << MsgVerb << " un numero de page dans l index ?" << endl;
- cin >> MotATrouv;
- while (( CurrentPtrMot != NULL ) && ( strcmp ( CurrentPtrMot -> ZoneMot , MotATrouv ) != 0 ))
- {
- PrecPtrMot = CurrentPtrMot;
- CurrentPtrMot = CurrentPtrMot -> PtrNextMot;
- }
- if ( CurrentPtrMot == NULL )
- {// si on est arrivé à la fin (sans trouver le mot correspondant)
- cout << endl << " Ce mot n est pas encore repris dans l index !!!" << endl;
- }
- else
- {
- if ( PushOrPop == 1 )
- {// insertion d'une page pour ce mot
- CurrentPtrMot = PushPgWiz ( CurrentPtrMot );
- }
- else
- {// suppression d'une page pour ce mot
- CurrentPtrMot = PopPg ( CurrentPtrMot );
- }
- TopPtrMot = Mot0Pg ( PrecPtrMot, TopPtrMot, CurrentPtrMot );
- }
- }
- else
- {
- cout << endl << "Il n y a pas de mot dans l index !!!" << endl << endl;
- }
- return TopPtrMot;
- }
- TypeMotPtr PushPgWiz ( TypeMotPtr CurrentPtrMot )
- {
- int Choix = 0;
- CurrentPtrMot = PushPg ( CurrentPtrMot );
- cout << " ";
- system("pause" );
- system("cls" );
- MenuPg();
- cin >> Choix;
- while ( Choix != 3 )
- {
- switch ( Choix )
- {
- case 1 :// entrer une page
- CurrentPtrMot = PushPg ( CurrentPtrMot );
- break;
- case 2:// retirer une page
- if ( !PageIsEmpty ( CurrentPtrMot -> PtrPremPg ) )
- {
- CurrentPtrMot = PopPg ( CurrentPtrMot );
- }
- else
- {
- cout << endl << " Il n'y a plus de page contenant ce mot" << endl;
- }
- break;
- default:
- cout << endl << endl<< " Ce Choix est incorecte !!! "<<endl;
- break;
- }
- system("pause" );
- system("cls" );
- MenuPg();
- cin >> Choix;
- }
- return CurrentPtrMot;
- }
- TypeMotPtr PushPg ( TypeMotPtr CurrentPtrMot )
- {
- int ValPg;
- TypePagePtr NewPtrPg;
- TypePagePtr PrecPtrPg;
- TypePagePtr CurrentPtrPg;
- PrecPtrPg = CurrentPtrMot -> PtrPremPg;
- CurrentPtrPg = CurrentPtrMot -> PtrPremPg;
- cout << "Entrez le numero de la page contenant le mot ..." << endl;
- ValPg = CinInt();
- if ( CurrentPtrMot -> PtrPremPg == NULL )
- {//insert premiere page
- NewPtrPg = new (TypePage);
- if (! TestAlloc ( NewPtrPg )) return 0;
- NewPtrPg -> PtrNextPg = CurrentPtrMot -> PtrPremPg;
- NewPtrPg -> NumPg = ValPg;
- CurrentPtrMot -> PtrPremPg = NewPtrPg;
- CurrentPtrMot -> PtrDernPg = NewPtrPg;
- CurrentPtrPg = CurrentPtrMot -> PtrPremPg;
- }
- else
- {
- while (( CurrentPtrPg != NULL ) && ( CurrentPtrPg -> NumPg < ValPg ))
- {
- PrecPtrPg = CurrentPtrPg;
- CurrentPtrPg = CurrentPtrPg -> PtrNextPg;
- }
- if ( CurrentPtrPg != NULL )
- {
- if ( CurrentPtrPg -> NumPg != ValPg)
- {// si le numero n'est pas encore repris dans l'index
- NewPtrPg = new (TypePage);
- if (! TestAlloc ( NewPtrPg )) return 0;
- NewPtrPg -> PtrNextPg = CurrentPtrPg;
- NewPtrPg -> NumPg = ValPg;
- if ( CurrentPtrPg == CurrentPtrMot -> PtrPremPg )
- {//insert en début
- CurrentPtrMot -> PtrPremPg = NewPtrPg;
- }
- else
- {//insert en milieu
- PrecPtrPg -> PtrNextPg = NewPtrPg;
- }
- }
- else
- {
- cout << endl<<" Cette page est deja repertoriee"<<endl;
- }
- }
- else
- {//insert en fin
- NewPtrPg = new (TypePage);
- if (! TestAlloc ( NewPtrPg )) return 0;
- NewPtrPg -> PtrNextPg = CurrentPtrPg;
- NewPtrPg -> NumPg = ValPg;
- PrecPtrPg -> PtrNextPg = NewPtrPg;
- CurrentPtrMot -> PtrDernPg = NewPtrPg;
- }
- }
- return CurrentPtrMot;
- }
- TypeMotPtr PopMot( TypeMotPtr TopPtrMot )
- {
- TypeMotPtr CurrentPtrMot = TopPtrMot;
- char * MotASup;
- TypeMotPtr PrecPtrMot = TopPtrMot;
- MotASup = new ( char );
- if (! TestAlloc ( MotASup )) return 0;
- if ( CurrentPtrMot != NULL )
- {
- SortirMots ( TopPtrMot );
- cout << endl << " Veuillez saisir le mot a supprimer ..." << endl;
- cin >> MotASup;
- while (( CurrentPtrMot != NULL ) && ( strcmp ( CurrentPtrMot -> ZoneMot , MotASup ) != 0))
- {// recherche du mot a supprimer
- PrecPtrMot = CurrentPtrMot;
- CurrentPtrMot = CurrentPtrMot -> PtrNextMot;
- }
- if ( CurrentPtrMot == NULL )
- {
- cout << endl << "Le mot \"" << MotASup << "\" n existe pas dans l index !" << endl;
- }
- else
- {
- cout << endl << " Le mot a supprimer etait : " << MotASup <<endl;
- if (CurrentPtrMot != TopPtrMot)
- {
- PrecPtrMot -> PtrNextMot = CurrentPtrMot -> PtrNextMot;
- }
- else
- {
- TopPtrMot = CurrentPtrMot -> PtrNextMot;
- }
- }
- }
- else
- {
- cout << endl << " Aucun mot dans l index !" << endl;
- }
- return TopPtrMot;
- }
- TypeMotPtr PopPg ( TypeMotPtr CurrentPtrMot )
- {
- TypePagePtr CurrentPtrPg = CurrentPtrMot -> PtrPremPg;
- TypePagePtr PrecPtrPg = CurrentPtrMot -> PtrPremPg;
- int PgASup;
- if ( CurrentPtrMot != NULL )
- {
- if ( CurrentPtrMot -> PtrPremPg != NULL )
- {
- SortirPages ( CurrentPtrMot );
- cout << endl << " Veuillez saisir la page a supprimer ..." << endl;
- PgASup = CinInt();
- while (( CurrentPtrPg != NULL ) && ( CurrentPtrPg -> NumPg != PgASup ))
- {// recherche de la page a supprimer
- PrecPtrPg = CurrentPtrPg;
- CurrentPtrPg = CurrentPtrPg -> PtrNextPg;
- }
- if ( CurrentPtrPg == NULL )
- {
- cout << endl << "La page " << PgASup << " n existe pas dans l index !" << endl;
- }
- else
- {
- cout << endl << " La page a supprimer etait la page no " << PgASup <<endl;
- if ( CurrentPtrPg != CurrentPtrMot -> PtrPremPg )
- {// chainage si suppresion du no au milieu ou en fin
- PrecPtrPg -> PtrNextPg = CurrentPtrPg -> PtrNextPg;
- if ( CurrentPtrPg == CurrentPtrMot -> PtrDernPg )
- {// si suppression de la derniere page de l'index pour un mot
- CurrentPtrMot -> PtrDernPg = PrecPtrPg;
- }
- }
- else
- {// chainage si suppression du no en début
- CurrentPtrMot -> PtrPremPg = CurrentPtrPg -> PtrNextPg;
- }
- }
- }
- else
- {
- cout << endl << " Ce mot ne figure dans aucune page !" << endl;
- }
- }
- else
- {
- cout << endl << " Aucun mot dans l index !" << endl;
- }
- return CurrentPtrMot;
- }
- TypeMotPtr Mot0Pg ( TypeMotPtr PrecPtrMot, TypeMotPtr TopPtrMot, TypeMotPtr CurrentPtrMot )
- {
- char OuiOuNon = 'x';
- if ( CurrentPtrMot -> PtrPremPg == NULL )
- {
- cout << endl << " Il n'y a plus de page contenant ce mot a present." << endl;
- while ( OuiOuNon != 'O' && OuiOuNon != 'o' && OuiOuNon != 'N' && OuiOuNon != 'n')
- {
- cout << " Desirez vous supprimer ce mot de l index ? (o/n) "<<endl;
- cin >> OuiOuNon;
- switch ( OuiOuNon )
- {
- case 'O' : case 'o' :
- if (CurrentPtrMot != TopPtrMot)
- {
- PrecPtrMot -> PtrNextMot = CurrentPtrMot -> PtrNextMot;
- }
- else
- {
- TopPtrMot = CurrentPtrMot -> PtrNextMot;
- }
- break;
- case 'N' : case 'n' :
- cout << endl << endl << "Ce mot, bien que n' etant repris dans aucune page,";
- cout << endl << "restera donc present dans l'index." << endl << endl;
- break;
- default :
- cout << endl << endl << "Cette reponse n'est pas correcte !" << endl;
- break;
- }
- }
- }
- return TopPtrMot;
- }
|
et enfin mon FctsOut.cpp
|