Advertisement
dimon-torchila

Untitled

Jan 7th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include "lab1.h"
  2. #include "lab2.h"
  3. #include "lab3.h"
  4. #include "test.h"
  5.  
  6. using namespace std;
  7.  
  8. void countingSort(lab::Queue& q){
  9. int mx = INT_MIN;
  10. int size = q.size();
  11. for(int i = 0; i < q.size(); ++i){
  12. int front = q.front();
  13. mx = max(mx, front);
  14. q.pop();
  15. q.push(front);
  16. }
  17. auto count = vector<int>(mx + 1, 0);
  18. for(int i = 0; i < size; ++i){
  19. int front = q.front();
  20. count[front]++;
  21. q.pop();
  22. }
  23. for(int i = 0; i < count.size(); ++i){
  24. for(int j = 0; j < count[i]; ++j){
  25. q.push(i);
  26. }
  27. }
  28. }
  29.  
  30. int main() {
  31. srand(time(nullptr));
  32. lab::Queue queue(20);
  33. for(int i = 0; i < queue.size(); ++i)
  34. queue.push(rand() % 10);
  35. queue.print();
  36. cout << endl;
  37. countingSort(queue);
  38. queue.print();
  39. }
  40.  
  41.  
  42. /*int main(){
  43. lab2::Graph G(4);
  44. set<int> visited;
  45. int cCount;
  46. cin >> cCount;
  47. for(int i = 0; i < cCount; ++i){
  48. string first_v, second_v;
  49. int weight;
  50. cin >> first_v >> second_v >> weight;
  51. G.Add_E(first_v, second_v, weight);
  52. }
  53. G.print();
  54. cout << endl;
  55. vector<string> ways = G.get_ways(8);
  56. for(int i = 0; i < ways.size(); ++i)
  57. cout << ways[i] << endl;
  58.  
  59. return 0;
  60. }*/
  61. /*
  62. 5
  63. a b 3
  64. b d 5
  65. b c 5
  66. c d 1
  67. d a 7
  68.  
  69. d e 2
  70. c e 6
  71. */
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement