Merge Sort
Description du code
Exemple de tri par fusionCode source ou contenu du fichier
Code Pascal (Merge Sort) (17 lignes)
function mergeSort(var a : array of integer; minIndex, maxIndex : integer); {Pre: a defined maxIndex>=minIndex; minIndex>=0; a[minIndex..maxIndex] defined Post: for each i into minIndex..maxIndex, a[maxIndex] >= a[i] } var center : integer; {center of the array} begin if minIndex > maxIndex {O(1)} then begin center := (minIndex + maxIndex) div 2; {O(1)} mergeSort(a, minIndex, center); {T(n/2)} mergeSort(a, center+1, maxIndex); {T(n/2)} merge(a, minIndex, center, maxIndex); {O(n)} end end;
Autres extraits de codes en Pascal
- Merge Sort Exemple de tri par fusion
- Selection Sort Exemple de tri par sélection
- Suite de Fibonacci Exemple de récursion en Pascal
- Suite de Fibonacci Exemple de méoïsation en Pascal
- Tous les extraits
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 05/10/2009, last modified the 28/10/2018
Source of the printed document:https://www.gaudry.be/en/sniplet-rf-pascal/tri-fusion.pas.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.