No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Merge Sort

Description du code

Exemple de tri par fusion

Code source ou contenu du fichier

  1. function mergeSort(var a : array of integer; minIndex, maxIndex : integer);
  2. {Pre: a defined
  3. maxIndex>=minIndex;
  4. minIndex>=0;
  5. a[minIndex..maxIndex] defined
  6.  Post: for each i into minIndex..maxIndex, a[maxIndex] >= a[i]
  7. }
  8. var center : integer; {center of the array}
  9. begin
  10. if minIndex > maxIndex {O(1)}
  11. then begin
  12. center := (minIndex + maxIndex) div 2; {O(1)}
  13. mergeSort(a, minIndex, center); {T(n/2)}
  14. mergeSort(a, center+1, maxIndex); {T(n/2)}
  15. merge(a, minIndex, center, maxIndex); {O(n)}
  16. end
  17. end;

Autres extraits de codes en Pascal

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.