Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include <time.h>
- int main()
- {
- int i;
- int a[] = {5, 3, 4, 9, 1, 2};
- int tam = ((int) (sizeof(a) / sizeof(a[0]))) - 1;
- quicksort(a, 0, tam);
- for(i = 0; i < tam+1; i++){
- printf("%d ", a[i]);
- }
- }
- void quicksort(int *a, int esq, int dir)
- {
- int pivot, i, j, temp;
- if(esq < dir) {
- pivot = esq;
- i = esq;
- j = dir;
- while(i < j) {
- while(a[i] <= a[pivot] && i <= dir)
- i++;
- while(a[j] > a[pivot] && j >= esq)
- j--;
- if(i < j) {
- temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- }
- temp = a[j];
- a[j] = a[pivot];
- a[pivot] = temp;
- quicksort(a, esq, j-1);
- quicksort(a, j+1, dir);
- }
- }
- int mediana(int tam){
- srand ( time(NULL));
- int v1, v2, v3;
- v1 = 0;
- v2 = 0;
- v3 = 0;
- while (v1 == v2 || v1 == v3 || v2 == v3){
- v1 = rand() % tam;
- v2 = rand() % tam;
- v3 = rand() % tam;
- }
- int aux;
- if (v1 > v2){
- aux = v1;
- v1 = v2;
- v2 = aux;
- }
- if (v1 > v3){
- aux = v1;
- v1 = v3;
- v3 = aux;
- }
- if(v2 > v3){
- aux = v2;
- v2 = v3;
- v3 = aux;
- }
- printf("%d %d %d\n", v1,v2,v3);
- return v2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement