Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include"kopiec.h"
  3. //sortowanie przez zliaczanie
  4. void CountingSort(int* input, int size, int m)
  5. {
  6. int *chwilowy = new int[m];
  7. int *output = new int[size];
  8.  
  9. for (int i = 0; i < m; i++)
  10. {
  11. chwilowy[i] = 0;
  12. }
  13. for (int i = 0; i < size; i++)
  14. {
  15. chwilowy[(input[i] - 1)] = chwilowy[(input[i] - 1)] + 1;
  16. }
  17. for (int i = 1; i < m; i++)
  18. {
  19. chwilowy[i] = chwilowy[i] + chwilowy[i - 1];
  20. }
  21. for (int i = size - 1; i >= 0; i--)
  22. {
  23. output[(chwilowy[(input[i] - 1)] - 1)] = input[i];
  24. chwilowy[(input[i] - 1)] = chwilowy[(input[i] - 1)] - 1;
  25. }
  26. memcpy(input, output, size * sizeof(int));
  27. }
  28. void BucketSort(int* A, int size)
  29. {
  30. //for (int i = 1; i <= length(A); i++) {
  31.  
  32. //}
  33. }
  34.  
  35. int main() {
  36. int table[10];
  37. for (int i = 0; i < 10; i++) {
  38. table[i] = 10 - i;
  39. std::cout << table[i] << " ";
  40. }
  41. std::cout <<std::endl;
  42. CountingSort(table, 10, 10);
  43. for (int i = 0; i < 10; i++) {
  44. std::cout << table[i] << " ";
  45. }
  46. getchar();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement