Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void insertionSort(int *vetor, int lenght)
  5. {
  6. int i,j,atual;
  7. for(i=0; i<lenght; i++)
  8. {
  9. atual = vetor[i];
  10. j = i-1;
  11.  
  12. while((j>=0)&&(atual<vetor[j]))
  13. {
  14. vetor[j + 1] = vetor[j];
  15. j = j-1;
  16. }
  17. vetor[j+1] = atual;
  18. }
  19. }
  20.  
  21. int Bucket(float *vetor,int n)
  22. {
  23. int i,j,indice,*D,rea = 10;
  24. float **B;
  25. B = (float**) malloc(n*sizeof(float*));
  26.  
  27. for(i=0;i<n;i++)
  28. {
  29. B[i] =(float*) calloc(10,sizeof(float));
  30. }
  31.  
  32. for(i=0;i<n;i++)
  33. {
  34. j = vetor[i]*n;
  35. B[j][0]++;
  36. if(B[j][0]>rea)
  37. {
  38. //B[j] = (float*) realloc(B[j],sizeof(float));
  39. //rea+=10;
  40. printf("\n\n\n\n\n\n\n\n FO \t DE \t O \n\n\n\n\n\n");
  41. scanf("ola: %d",&i);
  42. }
  43. indice = (int)B[j][0];
  44. B[j][indice] = vetor[i];
  45.  
  46. }
  47.  
  48. for(i=0;i<n;i++)
  49. {
  50. indice = B[i][0];
  51. for(j=0;j<indice;j++)
  52. {
  53. vetor[i]=B[i][j+1];
  54. }
  55. }
  56. return 1;
  57.  
  58. }
  59.  
  60.  
  61. int main()
  62. {
  63. int n=150;
  64. float *vetor;
  65. vetor = (float*) malloc(sizeof(float)*n);
  66. int i;
  67.  
  68. for(i=n-1;i>=0;i--){
  69.  
  70. vetor[i] = (float)i/n;
  71. }
  72.  
  73. Bucket(vetor,n);
  74.  
  75.  
  76. for(i=0;i<n;i++)
  77. printf("%f\n",vetor[i]);
  78.  
  79. return 1;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement