Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // CV05
- //
- // Created by Petr Němeček on 21/10/14.
- // Copyright (c) 2014 Petr Němeček. All rights reserved.
- //
- #include <iostream>
- class Pole { int *pole;
- const unsigned n;
- unsigned pocet;
- public:
- Pole(unsigned n) :n(n) {
- pole = new int[n];
- pocet = 0; }
- ~Pole() { delete[] pole; }
- bool pridat(int c) {
- for (int i = 0; i < pocet; i++) {
- if (pole[i] == c) {
- return false;
- }
- }
- pole[pocet++] = c;
- return true;
- }
- friend void vypsat(const Pole &);
- friend bool zrusit(Pole &,int c);
- };
- void vypsat( const Pole &p )
- {
- for (int i = 0; i < p.pocet; i++) {
- std::cout << p.pole[i] << ", ";
- }
- std::cout << std::endl;
- }
- bool zrusit( Pole &p, int c )
- {
- bool isPresent = false;
- int i;
- for (i = 0; i < p.pocet; i++) {
- if (p.pole[i] == c) {
- isPresent = true;
- break;
- }
- }
- if (isPresent == true) {
- int tmp;
- for (int j = i; j < p.pocet - 1 ; j++) {
- tmp = p.pole[j];
- p.pole[j] = p.pole[j + 1];
- p.pole[j + 1] = tmp;
- }
- p.pocet--;
- return true;
- } else {
- return false;
- }
- }
- int main(int argc, const char * argv[]) {
- Pole p(10);
- p.pridat(1);
- p.pridat(3);
- p.pridat(5);
- p.pridat(7);
- p.pridat(5);
- p.pridat(2);
- p.pridat(4);
- p.pridat(6);
- vypsat(p);
- zrusit(p, 2);
- vypsat(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement