Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- class Human
- {
- public:
- string Name, Surname;
- int Age;
- Human(){};
- Human(string N, string S, int A):Name(N), Surname(S), Age(A){};
- ~Human(){};
- };
- int MaxAge(const vector<Human> vec)
- {
- Human Max = vec[0];
- for (int i = 1; i < vec.size(); i++)
- if (vec[i].Age > Max.Age)
- Max = vec[i];
- return Max.Age;
- };
- void countingSort(const vector<Human> &a, vector<Human> &b)
- {
- int k = MaxAge(a);
- k++;
- vector<int> c(k);
- for (int i = 0; i < a.size(); i++)
- c[ a[i].Age ]++;
- for (int i = 1; i < k; i++)
- c[i] += c[i - 1];
- for (int i = a.size() - 1; i >= 0; i--)
- {
- b[ c[ a[i].Age ] - 1 ] = a[i];
- c[ a[i].Age ]--;
- };
- };
- int main()
- {
- system("COLOR F0");
- srand( time(NULL) );
- vector<Human> a;
- /*
- a ვექტორის შევსება ფაილიდან ან ხელით
- ...
- */
- vector<Human> b(a.size());
- for (int i = 0; i < a.size(); i++)
- cout << " a [ " << i << " ]\t= " << a[i].Age << endl;
- cout << endl;
- countingSort(a, b);
- for (int i = 0; i < b.size(); i++)
- cout << " b [ " << i << " ]\t= " << b[i].Age << endl;
- cout << endl;
- system("PAUSE");
- return (0);
- };
Advertisement
Add Comment
Please, Sign In to add comment