- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- #include <string>
- using namespace std;
-
- typedef struct{
- string telephone;
- string nom;
- string prenom;
- string surnom;
- }fi;
-
- void TriMaximier(fi* tableau_a_trier,long n,fi* tableau_trie)
- {
- long index_plus_petit,index,index_tableau_trie=0;
- while(n>=1)
- {
- index_plus_petit=0;
- for(index=1;index<n;index++)
- {
- if(tableau_a_trier[index_plus_petit].telephone>tableau_a_trier[index].telephone)
- {
- index_plus_petit=index;
- }
- }
- tableau_trie[index_tableau_trie]=tableau_a_trier[index_plus_petit];
- index_tableau_trie++;
- for(index=index_plus_petit;index<n-1;index++)
- {
- tableau_a_trier[index]=tableau_a_trier[index+1];
- }
- n--;
- }
- }
-
- void TriSelection(fi* Tab,long TailleTab)
- {
- long Idebut,Ipetit,Iparcours;
- fi Buffer;
- for(Idebut=0;Idebut<TailleTab-1;Idebut++)
- {
- Ipetit=Idebut;
- for(Iparcours=Idebut+1;Iparcours<TailleTab;Iparcours++)
- {
- if(Tab[Ipetit].nom>Tab[Iparcours].nom)
- {
- Ipetit=Iparcours;
- }
- }
- Buffer=Tab[Ipetit];
- Tab[Ipetit]=Tab[Idebut];
- Tab[Idebut]=Buffer;
- }
- }
-
- int main(void)
- {
- fi fiche;
- fi *Tab;
- fi *Tab_trie;
- long taille;
- cout<<"Entrez le nombre de fiches a enregistrer"<<endl;
- cin>>taille;
- Tab=new fi[taille];
- if(Tab==NULL)
- {
- cout<<"Echec de l'allocation memoire"<<endl;
- }
- else
- {
- for(long index=0;index<taille;index++)
- {
- cout<<"Entrez les informations de la fiche "<<index+1<<" : "<<endl;;
- cout<<"Nom: ";
- cin>>Tab[index].nom;
- cout<<"Nunmero de telephone: ";
- cin>>Tab[index].telephone;
- cout<<"Prenom: ";
- cin>>Tab[index].prenom;
- cout<<"Surnom: ";
- cin>>Tab[index].surnom;
- clrscr();
- }
- Tab_trie=new fi[taille];
- if(Tab_trie==NULL)
- {
- cout<<"Echec de la 2eme allocation memoire"<<endl;
- delete[] Tab;
- }
- else
- {
- TriMaximier(Tab,taille,Tab_trie);
- cout<<"Voici le tableau trie par telephone par la methode du tri maximier:\n"<<endl;
- for(long index=0;index<taille;index++)
- {
- cout<<Tab_trie[index].telephone<<" "<<Tab_trie[index].nom<<" "<<Tab_trie[index].prenom<<" "<<Tab_trie[index].surnom<<endl;
- }
- cout<<endl;
- delete[] Tab;
- TriSelection(Tab_trie,taille);
- cout<<"Voici le tableau trie par nom par la methode du tri par selection:\n"<<endl;
- for(long index=0;index<taille;index++)
- {
- cout<<Tab_trie[index].nom<<" "<<Tab_trie[index].prenom<<" "<<Tab_trie[index].surnom<<" "<<Tab_trie[index].telephone<<endl;
- }
- cout<<endl;
- delete[] Tab_trie;
- }
- }
- system("PAUSE");
- return 0;
- }
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <string>
using namespace std;
typedef struct{
string telephone;
string nom;
string prenom;
string surnom;
}fi;
void TriMaximier(fi* tableau_a_trier,long n,fi* tableau_trie)
{
long index_plus_petit,index,index_tableau_trie=0;
while(n>=1)
{
index_plus_petit=0;
for(index=1;index<n;index++)
{
if(tableau_a_trier[index_plus_petit].telephone>tableau_a_trier[index].telephone)
{
index_plus_petit=index;
}
}
tableau_trie[index_tableau_trie]=tableau_a_trier[index_plus_petit];
index_tableau_trie++;
for(index=index_plus_petit;index<n-1;index++)
{
tableau_a_trier[index]=tableau_a_trier[index+1];
}
n--;
}
}
void TriSelection(fi* Tab,long TailleTab)
{
long Idebut,Ipetit,Iparcours;
fi Buffer;
for(Idebut=0;Idebut<TailleTab-1;Idebut++)
{
Ipetit=Idebut;
for(Iparcours=Idebut+1;Iparcours<TailleTab;Iparcours++)
{
if(Tab[Ipetit].nom>Tab[Iparcours].nom)
{
Ipetit=Iparcours;
}
}
Buffer=Tab[Ipetit];
Tab[Ipetit]=Tab[Idebut];
Tab[Idebut]=Buffer;
}
}
int main(void)
{
fi fiche;
fi *Tab;
fi *Tab_trie;
long taille;
cout<<"Entrez le nombre de fiches a enregistrer"<<endl;
cin>>taille;
Tab=new fi[taille];
if(Tab==NULL)
{
cout<<"Echec de l'allocation memoire"<<endl;
}
else
{
for(long index=0;index<taille;index++)
{
cout<<"Entrez les informations de la fiche "<<index+1<<" : "<<endl;;
cout<<"Nom: ";
cin>>Tab[index].nom;
cout<<"Nunmero de telephone: ";
cin>>Tab[index].telephone;
cout<<"Prenom: ";
cin>>Tab[index].prenom;
cout<<"Surnom: ";
cin>>Tab[index].surnom;
clrscr();
}
Tab_trie=new fi[taille];
if(Tab_trie==NULL)
{
cout<<"Echec de la 2eme allocation memoire"<<endl;
delete[] Tab;
}
else
{
TriMaximier(Tab,taille,Tab_trie);
cout<<"Voici le tableau trie par telephone par la methode du tri maximier:\n"<<endl;
for(long index=0;index<taille;index++)
{
cout<<Tab_trie[index].telephone<<" "<<Tab_trie[index].nom<<" "<<Tab_trie[index].prenom<<" "<<Tab_trie[index].surnom<<endl;
}
cout<<endl;
delete[] Tab;
TriSelection(Tab_trie,taille);
cout<<"Voici le tableau trie par nom par la methode du tri par selection:\n"<<endl;
for(long index=0;index<taille;index++)
{
cout<<Tab_trie[index].nom<<" "<<Tab_trie[index].prenom<<" "<<Tab_trie[index].surnom<<" "<<Tab_trie[index].telephone<<endl;
}
cout<<endl;
delete[] Tab_trie;
}
}
system("PAUSE");
return 0;
}