allekco

Piramidal sort

Oct 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <stddef.h>
  6. #include <time.h>
  7.  
  8. int randomazer (int max, int min){
  9. float random;
  10. random = rand();
  11. random = (random / RAND_MAX) * (max-min) + min;
  12. return((int)random);
  13. }
  14.  
  15. void swap (int *a1, int *a2)
  16. {
  17. int tmp = *a1;
  18. *a1 = *a2;
  19. *a2 = tmp;
  20. }
  21.  
  22.  
  23. int main (void){
  24. srand(time(NULL));
  25. int N, i, k1, k2, note;
  26. scanf ("%d", &N);
  27. int x[N+1];
  28. for (i=0 ; i<N ; i++){
  29. x [i] = randomazer (0, 100);
  30. printf ("%d ", x[i]);
  31. }
  32.  
  33. k1 = (N-2)*5;
  34. k2 = (N-3)*5;
  35.  
  36. if (k1%10 == 0){
  37. i = k1/10;
  38. note = 1; //only left
  39. }
  40. if (k2%10 == 0){
  41. i = k2/10;
  42. note = 2; //left and right
  43. }
  44.  
  45. printf ("\n %d \n", i);
  46.  
  47. if (note == 2){
  48. while (i != 0){
  49.  
  50. if ((a[i]<a[2*i+1])||(a[i]<a[2*i+2])){
  51. if (a[2*i+1]>=a[2*i+1]){
  52. swap (&a[i], &a[2*i+1]);
  53. //again this function while
  54.  
  55. }
  56. else{
  57. swap (&a[i], &a[2*i+2]);
  58. //again this function
  59. }
  60. }
  61.  
  62. i--;
  63. }
  64.  
  65. }
  66.  
  67. if(note == 1){
  68.  
  69.  
  70. }
  71.  
  72.  
  73. return 0;
  74. }
Add Comment
Please, Sign In to add comment