Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #ifndef DEBUG
  4. #define DEBUG(...) printf(__VA_ARGS__)
  5. #endif
  6. void bubble_sort(int a[], int br[]){
  7. int i, j, tmp;
  8. for(i = 1; i <= 10; i++){
  9. for(j = 2; j <= 10; j++){
  10. if(a[j-1] < a[j]){
  11. tmp = a[j-1];
  12. a[j-1] = a[j];
  13. a[j] = tmp;
  14.  
  15. tmp = br[j-1];
  16. br[j-1] = br[j];
  17. br[j] = tmp;
  18. }
  19. }
  20. }
  21. for(i = 1; i <= 10; i++){
  22. if(a[i] == 0) continue;
  23. printf("%d\t", br[i]);
  24. }
  25. printf("\n");
  26. for(i = 1; i <= 10; i++){
  27. if(a[i] == 0) continue;
  28. printf("%d\t", a[i]);
  29. }
  30. }
  31. /*void selection_sort(int a[], int br[]){
  32. int i, j, max, tmp, n=10;
  33. for(i = 1; i <= n - 1; i++){
  34. max = i;
  35. for(j = i + 1; j <=n; j++){
  36. if(a[j] > max){
  37. max = j;
  38. }
  39. }
  40. tmp = a[max];
  41. a[max] = a[i];
  42. a[i] = tmp;
  43.  
  44. tmp = br[max];
  45. br[max] = br[i];
  46. br[i] = tmp;
  47.  
  48. }
  49. for(i = 1; i <= 10; i++){
  50. printf("%d ", a[i]);
  51. }
  52. printf("\n");
  53. for(i = 1; i <= 10; i++){
  54. printf("%d ", br[i]);
  55. }
  56. }*/
  57. void bucket_sort(int in[], int out[], int n){
  58. int i, br[10]={0};
  59. for(i = 1; i <= n; i++){
  60. out[in[i]]++;
  61. }
  62. for(i = 1; i <= 10; i++){
  63. br[i]= i;
  64. }
  65. /*for(i = 1; i <= 10; i++){
  66. printf("%d ",br[i]);
  67. }
  68. printf("\n");
  69.  
  70. for(i = 1; i <= 10; i++){
  71. printf("%d ",out[i]);
  72. }*/
  73.  
  74. //selection_sort(out, br);
  75. bubble_sort(out, br);
  76. }
  77.  
  78. int main() {
  79. int polje[1000], out[1000]={0}, i=1, counter=0;
  80. while(1){
  81. scanf("%d", &polje[i]);
  82. if(polje[i]==0)break;
  83. i++;
  84. counter++;
  85. }
  86.  
  87. /*for(i = 1; i <=counter; i++){
  88. printf("%d ", polje[i]);
  89. }*/
  90. bucket_sort(polje, out, counter);
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement