Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C Algorithme de tri

Yash_

New Coder
Svp aider moi dans mon code pour trier par la methode du tri rapide, j'essais d'implementer en C pour trier un tableau d
C:
/*fonction partionner(T: Tableau d'entiers; imin,imax: entier): entier
Var pivot, i, j, temp: entier
Début
pivot ← T[imax]
i ← imin
j ← imax-1
Tant que i<=j faire
Tant que i<imax et T[i] <= pivot faire
i ← i+1
Fin Tant que
Tant que j>=imin et T[j] >= pivot faire
j ← j-1
Fin Tant que
Si i<j alors {échange }
temp ← T[i]
T[i] ← T[j]
T[j] ← temp
FinSi
Fin Tant que
T[imax] ← T[i]
T[i] ← pivot
Retourner i
Fin
procédure triRapide(T: Tableau d'entiers: imin,imax: entier)
Var position_pivot : entier
Début
Si imin < imax alors
position_pivot ← partitionner(T, imin, imax)
tri_rapide(T, imin, position_pivot - 1)
tri_rapide(T, position_pivot + 1, imax)
FinSi
Fin
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int partitionner(int *T, int imin, int imax)
{
 int pivot,i,j, temp;
 int pivot = T[imax], i = imin, j = imax-1 ;
 temp int ;
 tandis que
 {
 fais
 tandis que (i<imax & T[i] <= pivot);
 je++ ; // On fait croire que je
 fais
 tandis que (j>=imin & T[j] >= pivot);
 j-- ; // On fait décroite j
 si (je < j)
 {
 temp = T[i] ;
 T[i] = T[j] ;
 T[j] = temp ;
 }
 autre
 T[imax] ← T[i]
 T[i] ← pivot
 retourner je ;
 }
}
void triRrapide(int T[], int imin, int imax)
{
 int pivot ;
 si(imin < imax)
 {
 pivot = partitionner(T,imin, imax);
 tri_rapide(T, imin, pivot-1);
 tri_rapide(T, pivot+1, imax);
 }
}
e taille 100 mais sa ne marche pas et je demande de l'aide.
 
EN:
I don't think code can be written in any language other than english?

FR:
Je ne pense pas que le code puisse être écrit dans une autre langue que l'anglais?
 
@Johna, I have seen code elsewhere online, written in Italian and I'm pretty sure Japanese or Korean.
Nevermind, I now see the problem...

I wish I could speak French to communicate with you @Yash_, but unfortunately I need to have this bit translated:
C a été conçu pour être utilisé en anglais. Vous utilisez des mots-clés supposés que le compilateur ne comprendra pas au moment de la compilation. Vous devrez changer tous les mots français en anglais (si vous en connaissez, bien sûr).

Par exemple : fais = do, tandis que = while, etc.

J'espère que cela vous aidera !
 
EN:
I don't think code can be written in any language other than english?
If you studiously want to avoid any word not in your own language (as I think some French do), you can do so in C thanks to the preprocessor. Although not shown here, I suspect there may be a bunch of statements like these

C:
#define si if
#define autre else
#define tandis while
#define que
#define retourner return
#define fais do

This would make the OP's code compile cleanly, apart from these two lines

C:
 T[imax] ← T[i]
 T[i] ← pivot
which do not look like valid C to me, unless there also is a #define for . And even then there are missing semicolons, and I think, by looking at the context, these two lines may need surrounding brackets.

On the other hand it would not surprise me if there exists a cmpletely localized French version of C 😁
 
Last edited by a moderator:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom