High-Tech
Santé-Médecine
Droit-Finances
CodeS-SourceS
Inscription
Plan
Connexion
Rechercher un code, un tuto, une réponse
Accueil
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Tous les langages
Delphi / Pascal
Java
Python
SQL
RegEx
Flash
ASM
IRC
Graphisme
PDA
ColdFusion
Foxpro
Flex
Visual Basic / VB.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
PHP
Forum
Tutoriels
Codes Sources
Snippets
Top membres
C/C++/C++.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Javascript
Forum
Tutoriels
Codes Sources
Snippets
Top membres
C#/.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
ASP/ASP.NET
Forum
Tutoriels
Codes Sources
Snippets
Top membres
Accueil
Connexion
Déposer un code
Code
Recherche
Haut
Forum
Commentaires sur une source
Sujet Précédent
Sujet Suivant
FUSION DE DEUX TABLEAUX TRIÉS DANS UN TABLEAU TRIÉ ÉGALEMENT
MERY2000
Messages postés
3
Date d'inscription
lundi 17 octobre 2005
Statut
Membre
Dernière intervention
13 juillet 2007
- 13 juil. 2007 à 02:08
seddik_benz -
6 déc. 2013 à 20:34
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
https://codes-sources.commentcamarche.net/source/30102-fusion-de-deux-tableaux-tries-dans-un-tableau-trie-egalement
seddik_benz
6 déc. 2013 à 20:34
#include <cstdlib>
#include <iostream>
using namespace std;
struct noeud{int v; noeud *next;};
//_______________________________________________________________________
noeud* construit(){
noeud* p=NULL;
noeud* q=NULL;
noeud* l=NULL;
int nb_n,i,x;
i=1;
cout<<"Donnez le nombre des noeud de la liste :"<<endl;
cin>>nb_n;
while(i<=nb_n){
cout<<"Donnez un nombre entie "<<i<<endl;
cin>>x;
if(l == NULL){
l=new(noeud);
l->v=x;
l->next= NULL;
p=l;
}
else{
q=new(noeud);
q->v=x;
q->next= NULL;
p->next=q;
p=q;
}
i++;
}
return l;
}
//_______________________________________________________________________
void afficher(noeud* l){
int x;
noeud* p=l;
while(p!= NULL){
x=p->v;
cout<<x<<",";
p=p->next;
}
}
//_______________________________________________________________________
noeud* fusionner(noeud* p,noeud* q)
{
if (p == NULL)
return q ;
else if (q == NULL)
return p;
else if ((p->v) <= (q->v))
{
p->next = fusionner(p->next,q);
return p;
}
else
{
q->next = fusionner(p,q->next);
return q;
}
}
//_______________________________________________________________________
int main(int argc, char *argv[]){
cout<<"Construction Liste 1 :"<<endl;
noeud* l1=construit();
cout<<"Liste 1 = { ";afficher(l1);cout<<" } ."<<endl; // Liste 1
cout<<"___________________________"<<endl<<endl;
cout<<"Construction Liste 2 :"<<endl;
noeud* l2=construit();
cout<<"Liste 2 = { ";afficher(l2);cout<<" } ."<<endl; // Liste 2
cout<<"___________________________"<<endl<<endl;
noeud* f= fusionner(l1,l2);
cout<<"Liste Fusionne = { ";afficher(f);cout<<" } ."<<endl; // Liste fusionner
system("PAUSE");
return EXIT_SUCCESS;
}
mahfoudh1986
Messages postés
5
Date d'inscription
samedi 19 juin 2010
Statut
Membre
Dernière intervention
1 septembre 2011
20 mai 2011 à 01:53
c est tres bon mes freres en avances
MERY2000
Messages postés
3
Date d'inscription
lundi 17 octobre 2005
Statut
Membre
Dernière intervention
13 juillet 2007
13 juil. 2007 à 02:08
Extra :)!!!merci bcp
Votre réponse
Discussions similaires
Les tableaux - constructeur
axelvdk
-
15 mars 2012 à 16:00
axelvdk
-
15 mars 2012 à 16:22
Turbo C++
cs_jrod
-
17 sept. 2002 à 23:27
cmarsc
-
19 sept. 2002 à 10:22
Etablir toutes les combinaisons possibles du Lotto
KBNchapal
-
2 févr. 2009 à 19:11
Mikaels35
-
3 févr. 2009 à 19:51
TURBO C++ et blocks que choisir
norman bates
-
14 oct. 2006 à 21:38
Vale Erian
-
15 oct. 2006 à 01:35
afficher un tableau en php
Larose_1921
-
18 avril 2020 à 16:00
s
-
6 mai 2020 à 18:11
Rejoignez-nous
A voir également
Afficher un tableau php en html
Retourner un tableau en c
Tri fusion c
Tableau decimal
Retourner un tableau
6 déc. 2013 à 20:34
#include <iostream>
using namespace std;
struct noeud{int v; noeud *next;};
//_______________________________________________________________________
noeud* construit(){
noeud* p=NULL;
noeud* q=NULL;
noeud* l=NULL;
int nb_n,i,x;
i=1;
cout<<"Donnez le nombre des noeud de la liste :"<<endl;
cin>>nb_n;
while(i<=nb_n){
cout<<"Donnez un nombre entie "<<i<<endl;
cin>>x;
if(l == NULL){
l=new(noeud);
l->v=x;
l->next= NULL;
p=l;
}
else{
q=new(noeud);
q->v=x;
q->next= NULL;
p->next=q;
p=q;
}
i++;
}
return l;
}
//_______________________________________________________________________
void afficher(noeud* l){
int x;
noeud* p=l;
while(p!= NULL){
x=p->v;
cout<<x<<",";
p=p->next;
}
}
//_______________________________________________________________________
noeud* fusionner(noeud* p,noeud* q)
{
if (p == NULL)
return q ;
else if (q == NULL)
return p;
else if ((p->v) <= (q->v))
{
p->next = fusionner(p->next,q);
return p;
}
else
{
q->next = fusionner(p,q->next);
return q;
}
}
//_______________________________________________________________________
int main(int argc, char *argv[]){
cout<<"Construction Liste 1 :"<<endl;
noeud* l1=construit();
cout<<"Liste 1 = { ";afficher(l1);cout<<" } ."<<endl; // Liste 1
cout<<"___________________________"<<endl<<endl;
cout<<"Construction Liste 2 :"<<endl;
noeud* l2=construit();
cout<<"Liste 2 = { ";afficher(l2);cout<<" } ."<<endl; // Liste 2
cout<<"___________________________"<<endl<<endl;
noeud* f= fusionner(l1,l2);
cout<<"Liste Fusionne = { ";afficher(f);cout<<" } ."<<endl; // Liste fusionner
system("PAUSE");
return EXIT_SUCCESS;
}
20 mai 2011 à 01:53
13 juil. 2007 à 02:08