Skip to content
Snippets Groups Projects
Commit 88345dcd authored by Vojtěch Novotný's avatar Vojtěch Novotný
Browse files

cviceni 3

parent 14de5451
No related branches found
No related tags found
1 merge request!4stabilni verze semestralni prace, 3 cviceni, domaci ukol 1
#include <vector>
#include <iostream>
#include <algorithm>
int main()
{
// neinicializovaný vektor cisel typu int, nulové velikosti
std::vector<int> a;
std::cout << "velikost a je " << a.size() << std::endl;
a.push_back(10);
std::cout << "velikost a je " << a.size() << std::endl;
a.resize(10);
for (int i = 0; i < a.size(); i++)
{
std::cout << a[i] << " ";
}
std::cout << std::endl;
// std::vector<int>::iterator i;
for (auto i = a.begin(); i != a.end(); i++)
{
std::cout << *i << " ";
}
std::cout << std::endl;
for (int x : a)
std::cout << x << " ";
std::cout << std::endl;
for (int &x : a)
x = 5;
for (const int &x : a)
std::cout << x << " ";
std::cout << std::endl;
int b[] = {1, 2, 3, 4};
int *pb = &b[1];
// pb+1 ukazatel
std::cout << *(pb + 1) << std::endl;
int &rb = b[1];
std::cout << rb + 10 << std::endl;
for (auto i = a.begin(); i != a.end() + 1; i++)
{
std::cout << *i << " ";
}
std::cout << std::endl;
try
{
for (int i = 0; i < a.size(); i++)
{
std::cout << a[i] << "/" << a.at(i) << " ";
}
throw 1;
std::cout << std::endl;
}
catch (std::out_of_range &e)
{
std::cerr << "chyba: " << e.what() << std::endl;
}
catch (int e)
{
std::cerr << "\n chyba" << e << std::endl;
}
std::vector<int> z{10, 11, 9, 8, 65, 3, 100};
for (int &x : z)
std::cout << x << " ";
std::cout << std::endl;
std::sort(z.begin(), z.end(), [](int a, int b)
{ return a > b; });
for (int &x : z)
std::cout << x << " ";
std::cout << std::endl;
std::vector<int> zz(z.size());
std::copy_if(z.begin(), z.end(), zz.begin(), [](int a)
{if(a>10) return a; else return 0; });
for (int &x : zz)
std::cout << x << " ";
std::cout << std::endl;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment