Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- double f(vector<double> t)
- {
- // skopiowanie tablicy
- vector<double> temp = t;
- // sortowanie bąbelkowe:
- for(unsigned i = 0; i < temp.size() - 1; ++i)
- {
- for(unsigned j = 0; j < temp.size() - 1 - i; ++j)
- if(temp[j] > temp[j + 1])
- swap(temp[j], temp[j + 1]);
- }
- if(t.size() % 2 == 1)
- return temp[(temp.size() - 1) / 2];
- unsigned i = temp.size() / 2;
- return (temp[i] + temp[i - 1]) / 2;
- }
- int main()
- {
- srand(static_cast<unsigned>(time(nullptr)));
- vector<double> wektor;
- wektor.resize(10);
- for(unsigned i = 0; i < 10; ++i)
- {
- wektor[i] = 100.0 * rand() / RAND_MAX;
- cout << wektor[i] << '\t';
- }
- cout << endl << f(wektor);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement