Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
File added
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tri_rapide.h"
void triRapide(long* A, size_t n) {
sousTriRapide(A,0,n);
}
void sousTriRapide(long* A, size_t first, size_t size){
if(first+1 < size){
size_t middle = partition(A,first,size);
sousTriRapide(A,first,middle);
sousTriRapide(A,middle+1,size);
}
}
size_t partition(long* A, size_t first, size_t size) {
long pivot = A[size-1];
size_t i = first;
for(int j = first; j+2 <= size; j++){
if(A[j] <= pivot){
permuter(A,i,j);
i++;
}
}
permuter(A,i,size-1);
return i;
}
void permuter(long* A,size_t i,size_t j) {
long inter = A[i];
A[i] = A[j];
A[j] = inter;
}
#ifndef TRIS_R
#define TRIS_R
#include <stdint.h>
#include <stdlib.h>
void triRapide(long* A, size_t n);
void sousTriRapide(long* A, size_t first, size_t size);
size_t partition(long* A, size_t first, size_t size);
void permuter(long* A,size_t i,size_t j);
#endif //TRIS_H
\ No newline at end of file
File added
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
void affichertab(long* T, int s){
printf("[ ");
for(int i = 0; i < s-1; i++){
printf("%d , ",T[i]);
}
printf("%d ]\n",T[s-1]);
}
long* listeAlea(size_t longueur, size_t N){
long* liste = malloc(sizeof(long) * longueur);
for(size_t i = 0; i < longueur; i++){
liste[i] = rand() % N;
}
return liste;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
void affichertab(long* T, int s);
long* listeAlea(size_t longeur, size_t N);
\ No newline at end of file
File added