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.

AbstractSorter

Lisez d'abord l'énoncé, et essayez de résoudre l'exercice. Ensuite vous pouvez utiliser la boîte de sélection afin d'afficher le code correspondant.

Enoncé

Nous devons implémenter quelques algorithmes de tris pour un tableau.

Pour réaliser cela, il nous est demandé de respecter les consignes suivantes :

  • Créer une interface Sorter, avec la méthode sort(Comparable[]);
  • Créer une classe abstraite AbstractSorter qui implémente Sorter.
    AbstractSorter contient les méthodes suivantes :
    • swap(int,int) qui permute deux valeurs d'un tableau.
    • compare(Comparable,Comparable); qui utilise un comparateur selon l'ordre naturel.
    Une classe interne InternalComparator
    1. private class InternalComparator implements Comparator{
    2. public int compare(Object o1, Object o2) {
    3. return ((Comparable)o1).compareTo((Comparable)o2);
    4. }
    5. }
  • Créer une classe ExchangeSorter qui hérite de AbstractSorter et implémente sort(Comparable[]); en effectuant un tri à bulles.
  • Créer une classe InsertionSorter qui hérite de AbstractSorter et implémente sort(Comparable[]); en effectuant un tri par insertion.

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 14/06/2005, last modified the 08/08/2019
Source of the printed document:https://www.gaudry.be/en/javaex-rf-triangle.html/javaex-rf-abstractsorter.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.