Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void quicksort(int a[10],int first,int last, int k){
- int pivot,j,temp,i,aux,soma;
- for (i=0;i<k;i++){
- aux = rand()%a[i];
- soma=soma+aux;
- }
- soma=soma/k;
- pivot=soma;
- if(first<last){
- pivot=first;
- i=first;
- j=last;
- while(i<j){
- while(a[i]<=a[pivot]&&i<last)
- i++;
- while(a[j]>a[pivot])
- j--;
- if(i<j){
- temp=a[i];
- a[i]=a[j];
- a[j]=temp;
- }
- }
- temp=a[pivot];
- a[pivot]=a[j];
- a[j]=temp;
- quicksort(a,first,j-1,k);
- quicksort(a,j+1,last,k);
- }
- }
- int main(){
- int s,i,k;
- printf("Entre com o valor de k: \n");
- scanf("%d",&k);
- printf("Entre com o tamanho do vetor: \n");
- scanf("%d",&s);
- int *a = (int *) malloc(1000000 * sizeof(int));
- srand(time(NULL));
- for(i=0 ; i < s ; i++)
- a[i]=rand();
- quicksort(a,0,s-1,k);
- printf("Elementos ordenados: \n");
- for(i=0;i<s;i++)
- printf("%d\n",a[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement