SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Tri selection
Algorithme pascal
0) Procédure Tri_Select (VAR T :
Vect ; N : Entier )
1) Pour i de 1 à N-1 Faire
Pos_Min ← Fn Cherche_Min (T, i,
N)
Si Pos_Min ≠ i Alors
Proc Permute (T[i] , T[Pos_Min])
Fin Si
Fin Pour
2) Fin tri_Select
 Fonction Cherche
0) Fonction Cherche_Min (T :
Vect ; départ, N : Entier ) : Entier
1) Min ← T[départ]
2) Indice ← Départ
3) Pour j de départ + 1 à N Faire
Si T[j] < Min Alors Min ← T[j]
indice ← j
Fin Si
Fin Pour
4) Cherche_Min ← indice
5) Fin Cherche_Min
 Procédure Permute
0) Procédure Permute (VAR a, b :
Réel)
1) temp ← a
a ← b
b ← temp
2) Fin Permute
FUNCTION Cherche_Min (T : Vect
; depart, N : Integer) : Integer ;
VAR
j, indice : Integer ;
Min : Real ;
BEGIN
Min := T[depart] ;
Indice := depart ;
For j := depart + 1 To N Do
Begin
If (T[j] < Min) Then Begin
Min := T[j] ;
indice := j ;
End ;
End ;
Cherche_Min := indice ;
End ;
PROCEDURE Permute (VAR a, b
: Real ) ;
VAR Temp : Real ;
BEGIN
temp := a ;
a := b ;
b := temp ;
END ;
PROCEDURE Tri_Select (VAR T :
Vect ; N : Integer ) ;
VAR
i, Pos_Min : Integer ;
BEGIN
For i := 1 To N-1 Do
Begin
Pos_Min := Cherche_Min (T, i, N) ;
If Pos_Min <> i Then Permute (T[i]
, T[Pos_Min]) ;
Résumer sur les tris
End ;
END ;
Tri à bulles
0) Procédure Bulles (VAR T : Vect
; N : Entier)
1) Répéter
échange ← Faux
Pour i de 1 à N-1 Faire
Si (T[i] > T[i +1] ) Alors
Proc Permute (T[i], T[i+1])
échange ← Vrai
Fin Si
Fin Pour
Jusqu'à échange = Faux
2) Fin Bulles
 Procédure Permute
0) Procédure Permute (VAR a, b :
Réel)
1) temp ← a
a ← b
b ← temp
2) Fin Permute
PROCEDURE Permute (VAR a, b
: Real ) ;
VAR Temp : Real ;
BEGIN
temp := a ;
a := b ;
b := temp ;
END ;
PROCEDURE Bulles (VAR T :
Vect ; N : Integer ) ;
VAR
i : Integer ;
echange : Boolean ;
BEGIN
Repeat
echange := False ;
For i := 1 To N-1 Do
If (T[i] > T[i +1] ) Then
Begin
Permute (T[i], T[i+1]) ;
echange := True ;
End ;
Until (echange = False);
END ;
Tri par insertion
0) Procédure T_Insertion (VAR T :
Vect ; N : Entier)
1) Pour i de 2 à N Faire
Tmp ← T[i]
j ← i
Proc Décaler (T, j, Tmp)
T[j] ← Tmp
Fin Pour
2) Fin T_Insertion
Proc Décaler
0) Procédure Décaler (VAR T :
Vect; VAR p : Entier ; temporaire :
PROCEDURE Decaler (VAR T :
Vect; VAR p : Integer ; temporaire :
Integer) ;
BEGIN
While T[p -1] > Temporaire Do
Begin
T[p] := T[p-1] ;
p := p -1 ;
End ;
END ;
PROCEDURE T_Insertion (VAR T
: Vect ; N : Integer) ;
Réel)
1) Tant que (T[p -1] > Temporaire)
Faire
T[p] ← T[p-1]
p ← p -1
Fin tant que
2) Fin Décaler
VAR i, j: Integer ;
tmp : Real ;
BEGIN
For i:= 2 To N Do
Begin
Tmp := T[i] ;
j := i ;
Decaler (T, j, Tmp) ;
T[j] := Tmp ;
End ;
END ;
Tri Shell
0) Procédure Shell (N : entier;
VAR T :
Vect)
1) P ← 1
Tant Que (P< N) Faire
P ←(3* P +1)
Fin Tant Que
2) Tant Que (P ≠1) Faire
P ← P DIV 3
Pour c de P + 1 à N Faire
Si (T[c] < T[c-p]) Alors
Tmp ← T[c]
pos ← c
Tant Que (pos > P-1) et (T[pos-P]>
tmp) Faire
T[pos]← T[pos-P]
pos←pos-P
Fin Tant que
T[pos]← Tmp
Fin Si
Fin Pour
Fin Tant Que
3) Fin Shell
PROCEDURE Shell (VAR T : Vect
; N : Integer) ;
VAR
P, c, pos : Integer ;
Tmp : Real ;
BEGIN
P := 1 ;
While ( P < N) Do
Begin
p := (3* P +1) ;
End ;
While (P < > 1) Do
Begin
P := P DIV 3 ;
For c := P + 1 To N Do
Begin
If (T[c] < T[c-p]) Then
Begin
Tmp := T[c] ;
pos := c ;
While (pos > P-1) AND (T[pos-P]>
tmp) Do
Begin
T[pos] := T[pos-P] ;
pos := pos-P ;
End ; {End While }
T[pos] := Tmp ;
End ; {End If }
End ; {End For}
End ; {End While }
END ;
Tri par fusion
0) Procédure Fusionner (VAR T :
Vect ; N : Entier ; T1, T2 : Vect2 ;
N1, N2 : Entier)
1) c ← 0
2) c1← 1
3) c2 ← 1
4) Répéter
c←c+1
Si (T1 [c1] < T2 [c2])
Alors
T[c] ← T1 [c1]
C1←c1+1
Sinon
T[c] ← T2 [c2]
c2←c2+1)
Fin Si
Jusqu'à (c1 > N1) OU (c2 > N2)
5) Si (c1 > N1) Alors
Pour i de c2 à N2 Faire
T[c] ← T2[i]
c←c+1)
Fin Pour
Sinon
Pour i de c1 à N1 Faire
T[c] ← T1[i]
c←c+1
Fin Pour
Fin Si
6) Fin Fusionner
PROCEDURE Fusionner (VAR T
: Vect ; N : Integer ; T1, T2 : Vect2
; N1, N2 : Integer) ;
VAR
c, c1, c2, i : Integer ;
BEGIN
c := 0 ; c1 := 1; c2 := 1 ;
Repeat
If (T1 [c1] < T2 [c2]) Then Begin
T[c] := T1 [c1] ;
Inc (c1, 1) ;
End
Else
Begin
T[c] := T2 [c2] ;
Inc (c2, 1) ;
End ;
Inc (c, 1) ;
Until (c1 > N1) OR (c2 > N2) ;
If (c1 > N1) Then
For i := c2 TO N2 Do
Begin
T[c] := T2[i] ;
Inc (c, 1) ;
End
Else
For i := c1 TO N1 Do
Begin
T[c] := T1[i] ;
Inc (c, 1) ;
End ;
END ;

Weitere ähnliche Inhalte

Was ist angesagt?

Serie tri revision_3si
Serie tri revision_3siSerie tri revision_3si
Serie tri revision_3si
Riadh Harizi
 
Chapitre iv algorithmes de tri
Chapitre iv algorithmes de triChapitre iv algorithmes de tri
Chapitre iv algorithmes de tri
Sana Aroussi
 
Chapitre iii récursivité et paradigme diviser pour régner
Chapitre iii récursivité et paradigme diviser pour régnerChapitre iii récursivité et paradigme diviser pour régner
Chapitre iii récursivité et paradigme diviser pour régner
Sana Aroussi
 
Les algorithmes d'arithmetique
Les algorithmes d'arithmetiqueLes algorithmes d'arithmetique
Les algorithmes d'arithmetique
mohamed_SAYARI
 
47811458 exercices-systemes-echantillonnes
47811458 exercices-systemes-echantillonnes47811458 exercices-systemes-echantillonnes
47811458 exercices-systemes-echantillonnes
TRIKI BILEL
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximation
mohamed_SAYARI
 

Was ist angesagt? (19)

Résumer arithmétique
Résumer arithmétiqueRésumer arithmétique
Résumer arithmétique
 
Exercices pascal tous les chapitres
Exercices pascal tous les chapitresExercices pascal tous les chapitres
Exercices pascal tous les chapitres
 
Serie tri revision_3si
Serie tri revision_3siSerie tri revision_3si
Serie tri revision_3si
 
DCT1 4SI
DCT1  4SIDCT1  4SI
DCT1 4SI
 
Chapitre 4 récursivité
Chapitre 4 récursivitéChapitre 4 récursivité
Chapitre 4 récursivité
 
Chapitre iv algorithmes de tri
Chapitre iv algorithmes de triChapitre iv algorithmes de tri
Chapitre iv algorithmes de tri
 
Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018Corrige exercices pascal_fenni_2018
Corrige exercices pascal_fenni_2018
 
Chapitre iii récursivité et paradigme diviser pour régner
Chapitre iii récursivité et paradigme diviser pour régnerChapitre iii récursivité et paradigme diviser pour régner
Chapitre iii récursivité et paradigme diviser pour régner
 
Les algorithmes d'arithmetique
Les algorithmes d'arithmetiqueLes algorithmes d'arithmetique
Les algorithmes d'arithmetique
 
Chapitre 3 NP-complétude
Chapitre 3 NP-complétudeChapitre 3 NP-complétude
Chapitre 3 NP-complétude
 
Algorithmique programmation2018
Algorithmique programmation2018Algorithmique programmation2018
Algorithmique programmation2018
 
récursivité algorithmique et complexité algorithmique et Les algorithmes de tri
récursivité algorithmique et complexité algorithmique et Les algorithmes de trirécursivité algorithmique et complexité algorithmique et Les algorithmes de tri
récursivité algorithmique et complexité algorithmique et Les algorithmes de tri
 
Recursiviteeeeeeeeee
RecursiviteeeeeeeeeeRecursiviteeeeeeeeee
Recursiviteeeeeeeeee
 
Chapitre 6 hachage statique
Chapitre 6 hachage statiqueChapitre 6 hachage statique
Chapitre 6 hachage statique
 
Chapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court cheminChapitre 2 problème de plus court chemin
Chapitre 2 problème de plus court chemin
 
47811458 exercices-systemes-echantillonnes
47811458 exercices-systemes-echantillonnes47811458 exercices-systemes-echantillonnes
47811458 exercices-systemes-echantillonnes
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximation
 
Algorithmique et programmation en Pascal (résumé)
Algorithmique et programmation en Pascal (résumé)Algorithmique et programmation en Pascal (résumé)
Algorithmique et programmation en Pascal (résumé)
 
cours algorithme
cours algorithmecours algorithme
cours algorithme
 

Andere mochten auch

exercices-corriges-dalgorithmique
exercices-corriges-dalgorithmiqueexercices-corriges-dalgorithmique
exercices-corriges-dalgorithmique
fast xp
 
Devoirs Algorithme + correction pour 4 si
Devoirs Algorithme + correction pour 4 siDevoirs Algorithme + correction pour 4 si
Devoirs Algorithme + correction pour 4 si
Narûtö Bàl'Sèm
 
Serie algos approximationx
Serie algos approximationxSerie algos approximationx
Serie algos approximationx
mohamed_SAYARI
 
éNoncés+corrections bac2010
éNoncés+corrections bac2010éNoncés+corrections bac2010
éNoncés+corrections bac2010
Morom Bil Morom
 
éNoncés+corrections bac2008
éNoncés+corrections bac2008éNoncés+corrections bac2008
éNoncés+corrections bac2008
Morom Bil Morom
 

Andere mochten auch (20)

Cours php bac info
Cours php bac infoCours php bac info
Cours php bac info
 
Résumé javascript bac info
Résumé javascript bac infoRésumé javascript bac info
Résumé javascript bac info
 
Cours tic complet
Cours tic completCours tic complet
Cours tic complet
 
Correction
CorrectionCorrection
Correction
 
Exercices en turbo pascal sur les nombres
Exercices en turbo pascal sur les nombresExercices en turbo pascal sur les nombres
Exercices en turbo pascal sur les nombres
 
Serie2
Serie2Serie2
Serie2
 
exercices-corriges-dalgorithmique
exercices-corriges-dalgorithmiqueexercices-corriges-dalgorithmique
exercices-corriges-dalgorithmique
 
Sujet bac info 2012 g1, g2 et g3 avec correction
Sujet bac info 2012 g1, g2 et g3 avec correctionSujet bac info 2012 g1, g2 et g3 avec correction
Sujet bac info 2012 g1, g2 et g3 avec correction
 
Devoirs Algorithme + correction pour 4 si
Devoirs Algorithme + correction pour 4 siDevoirs Algorithme + correction pour 4 si
Devoirs Algorithme + correction pour 4 si
 
Cours complet Base de donne Bac
Cours complet Base de donne Bac Cours complet Base de donne Bac
Cours complet Base de donne Bac
 
Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)Travaux dirigés 1: algorithme & structures de données (corrigés)
Travaux dirigés 1: algorithme & structures de données (corrigés)
 
Auto formation *WinDev
Auto formation *WinDev Auto formation *WinDev
Auto formation *WinDev
 
Sujet bac info 2013 g1, g2 et g3 avec correction
Sujet bac info 2013 g1, g2 et g3 avec correctionSujet bac info 2013 g1, g2 et g3 avec correction
Sujet bac info 2013 g1, g2 et g3 avec correction
 
XA Secure | Whitepaper on data security within Hadoop
XA Secure | Whitepaper on data security within HadoopXA Secure | Whitepaper on data security within Hadoop
XA Secure | Whitepaper on data security within Hadoop
 
Serie algos approximationx
Serie algos approximationxSerie algos approximationx
Serie algos approximationx
 
bac info : série récursivité
bac info : série récursivitébac info : série récursivité
bac info : série récursivité
 
Tp4 - PHP
Tp4 - PHPTp4 - PHP
Tp4 - PHP
 
Programmation événementielle avec Windev
Programmation événementielle avec WindevProgrammation événementielle avec Windev
Programmation événementielle avec Windev
 
éNoncés+corrections bac2010
éNoncés+corrections bac2010éNoncés+corrections bac2010
éNoncés+corrections bac2010
 
éNoncés+corrections bac2008
éNoncés+corrections bac2008éNoncés+corrections bac2008
éNoncés+corrections bac2008
 

Ähnlich wie Resumer sur les tris (7)

Resume algorithme
Resume algorithmeResume algorithme
Resume algorithme
 
transparents-Algo-complexite.pdf
transparents-Algo-complexite.pdftransparents-Algo-complexite.pdf
transparents-Algo-complexite.pdf
 
éNoncés+corrections bac2009
éNoncés+corrections bac2009éNoncés+corrections bac2009
éNoncés+corrections bac2009
 
Correction td2
Correction td2Correction td2
Correction td2
 
S2 TP1 partie 2: traitement de signal numérique
S2 TP1 partie 2: traitement de signal numériqueS2 TP1 partie 2: traitement de signal numérique
S2 TP1 partie 2: traitement de signal numérique
 
5e8a000b9840a.pdf
5e8a000b9840a.pdf5e8a000b9840a.pdf
5e8a000b9840a.pdf
 
Exercice exponontielle
Exercice exponontielleExercice exponontielle
Exercice exponontielle
 

Kürzlich hochgeladen

Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
ikospam0
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
Faga1939
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdf
AmgdoulHatim
 
Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdf
ssuserc72852
 

Kürzlich hochgeladen (18)

Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film français
 
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdf
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.
 
Les roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptxLes roches magmatique géodynamique interne.pptx
Les roches magmatique géodynamique interne.pptx
 
Computer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptxComputer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptx
 
Chapitre 2 du cours de JavaScript. Bon Cours
Chapitre 2 du cours de JavaScript. Bon CoursChapitre 2 du cours de JavaScript. Bon Cours
Chapitre 2 du cours de JavaScript. Bon Cours
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaire
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film français
 
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetFormation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
 
Conférence Sommet de la formation 2024 : Développer des compétences pour la m...
Conférence Sommet de la formation 2024 : Développer des compétences pour la m...Conférence Sommet de la formation 2024 : Développer des compétences pour la m...
Conférence Sommet de la formation 2024 : Développer des compétences pour la m...
 
L application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxL application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptx
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdf
 
Formation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptxFormation qhse - GIASE saqit_105135.pptx
Formation qhse - GIASE saqit_105135.pptx
 
Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdf
 

Resumer sur les tris

  • 1. Tri selection Algorithme pascal 0) Procédure Tri_Select (VAR T : Vect ; N : Entier ) 1) Pour i de 1 à N-1 Faire Pos_Min ← Fn Cherche_Min (T, i, N) Si Pos_Min ≠ i Alors Proc Permute (T[i] , T[Pos_Min]) Fin Si Fin Pour 2) Fin tri_Select  Fonction Cherche 0) Fonction Cherche_Min (T : Vect ; départ, N : Entier ) : Entier 1) Min ← T[départ] 2) Indice ← Départ 3) Pour j de départ + 1 à N Faire Si T[j] < Min Alors Min ← T[j] indice ← j Fin Si Fin Pour 4) Cherche_Min ← indice 5) Fin Cherche_Min  Procédure Permute 0) Procédure Permute (VAR a, b : Réel) 1) temp ← a a ← b b ← temp 2) Fin Permute FUNCTION Cherche_Min (T : Vect ; depart, N : Integer) : Integer ; VAR j, indice : Integer ; Min : Real ; BEGIN Min := T[depart] ; Indice := depart ; For j := depart + 1 To N Do Begin If (T[j] < Min) Then Begin Min := T[j] ; indice := j ; End ; End ; Cherche_Min := indice ; End ; PROCEDURE Permute (VAR a, b : Real ) ; VAR Temp : Real ; BEGIN temp := a ; a := b ; b := temp ; END ; PROCEDURE Tri_Select (VAR T : Vect ; N : Integer ) ; VAR i, Pos_Min : Integer ; BEGIN For i := 1 To N-1 Do Begin Pos_Min := Cherche_Min (T, i, N) ; If Pos_Min <> i Then Permute (T[i] , T[Pos_Min]) ; Résumer sur les tris
  • 2. End ; END ; Tri à bulles 0) Procédure Bulles (VAR T : Vect ; N : Entier) 1) Répéter échange ← Faux Pour i de 1 à N-1 Faire Si (T[i] > T[i +1] ) Alors Proc Permute (T[i], T[i+1]) échange ← Vrai Fin Si Fin Pour Jusqu'à échange = Faux 2) Fin Bulles  Procédure Permute 0) Procédure Permute (VAR a, b : Réel) 1) temp ← a a ← b b ← temp 2) Fin Permute PROCEDURE Permute (VAR a, b : Real ) ; VAR Temp : Real ; BEGIN temp := a ; a := b ; b := temp ; END ; PROCEDURE Bulles (VAR T : Vect ; N : Integer ) ; VAR i : Integer ; echange : Boolean ; BEGIN Repeat echange := False ; For i := 1 To N-1 Do If (T[i] > T[i +1] ) Then Begin Permute (T[i], T[i+1]) ; echange := True ; End ; Until (echange = False); END ; Tri par insertion 0) Procédure T_Insertion (VAR T : Vect ; N : Entier) 1) Pour i de 2 à N Faire Tmp ← T[i] j ← i Proc Décaler (T, j, Tmp) T[j] ← Tmp Fin Pour 2) Fin T_Insertion Proc Décaler 0) Procédure Décaler (VAR T : Vect; VAR p : Entier ; temporaire : PROCEDURE Decaler (VAR T : Vect; VAR p : Integer ; temporaire : Integer) ; BEGIN While T[p -1] > Temporaire Do Begin T[p] := T[p-1] ; p := p -1 ; End ; END ; PROCEDURE T_Insertion (VAR T : Vect ; N : Integer) ;
  • 3. Réel) 1) Tant que (T[p -1] > Temporaire) Faire T[p] ← T[p-1] p ← p -1 Fin tant que 2) Fin Décaler VAR i, j: Integer ; tmp : Real ; BEGIN For i:= 2 To N Do Begin Tmp := T[i] ; j := i ; Decaler (T, j, Tmp) ; T[j] := Tmp ; End ; END ; Tri Shell 0) Procédure Shell (N : entier; VAR T : Vect) 1) P ← 1 Tant Que (P< N) Faire P ←(3* P +1) Fin Tant Que 2) Tant Que (P ≠1) Faire P ← P DIV 3 Pour c de P + 1 à N Faire Si (T[c] < T[c-p]) Alors Tmp ← T[c] pos ← c Tant Que (pos > P-1) et (T[pos-P]> tmp) Faire T[pos]← T[pos-P] pos←pos-P Fin Tant que T[pos]← Tmp Fin Si Fin Pour Fin Tant Que 3) Fin Shell PROCEDURE Shell (VAR T : Vect ; N : Integer) ; VAR P, c, pos : Integer ; Tmp : Real ; BEGIN P := 1 ; While ( P < N) Do Begin p := (3* P +1) ; End ; While (P < > 1) Do Begin P := P DIV 3 ; For c := P + 1 To N Do Begin If (T[c] < T[c-p]) Then Begin Tmp := T[c] ; pos := c ; While (pos > P-1) AND (T[pos-P]> tmp) Do Begin T[pos] := T[pos-P] ; pos := pos-P ; End ; {End While } T[pos] := Tmp ; End ; {End If } End ; {End For} End ; {End While }
  • 4. END ; Tri par fusion 0) Procédure Fusionner (VAR T : Vect ; N : Entier ; T1, T2 : Vect2 ; N1, N2 : Entier) 1) c ← 0 2) c1← 1 3) c2 ← 1 4) Répéter c←c+1 Si (T1 [c1] < T2 [c2]) Alors T[c] ← T1 [c1] C1←c1+1 Sinon T[c] ← T2 [c2] c2←c2+1) Fin Si Jusqu'à (c1 > N1) OU (c2 > N2) 5) Si (c1 > N1) Alors Pour i de c2 à N2 Faire T[c] ← T2[i] c←c+1) Fin Pour Sinon Pour i de c1 à N1 Faire T[c] ← T1[i] c←c+1 Fin Pour Fin Si 6) Fin Fusionner PROCEDURE Fusionner (VAR T : Vect ; N : Integer ; T1, T2 : Vect2 ; N1, N2 : Integer) ; VAR c, c1, c2, i : Integer ; BEGIN c := 0 ; c1 := 1; c2 := 1 ; Repeat If (T1 [c1] < T2 [c2]) Then Begin T[c] := T1 [c1] ; Inc (c1, 1) ; End Else Begin T[c] := T2 [c2] ; Inc (c2, 1) ; End ; Inc (c, 1) ; Until (c1 > N1) OR (c2 > N2) ; If (c1 > N1) Then For i := c2 TO N2 Do Begin T[c] := T2[i] ; Inc (c, 1) ; End Else For i := c1 TO N1 Do Begin T[c] := T1[i] ; Inc (c, 1) ; End ; END ;