Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Vector{
- public:
- const int _dc = 1;
- int _capacity;
- int _size;
- int *_data;
- Vector()
- {
- _capacity = _dc;
- _size = 0;
- _data = new int[_capacity];
- }
- void push(int key)
- {
- if(_capacity == _size)
- {
- _capacity += _dc;
- int *_temp = new int[_capacity];
- memcpy(_temp, _data, sizeof(int) * _size);
- delete []_data;
- _data = _temp;
- }
- _data[_size] = key;
- _size++;
- }
- class iterator{
- public:
- int *current;
- iterator(int *temp)
- {
- current = temp;
- }
- bool operator <=(iterator other)
- {
- return current <= other.current;
- }
- bool operator >=(iterator other)
- {
- return current >= other.current;
- }
- iterator& operator ++()
- {
- this->current++;
- return *this;
- }
- iterator operator ++(int)
- {
- iterator i = *this;
- current = ++current;
- return i;
- }
- iterator& operator --()
- {
- this->current--;
- return *this;
- }
- iterator operator --(int)
- {
- iterator i = *this;
- current = --current;
- return i;
- }
- int operator *()
- {
- return *current;
- }
- };
- iterator begin()
- {
- return iterator(_data);
- }
- iterator end()
- {
- return iterator(_data + _size - 1);
- }
- };
- int main()
- {
- Vector vector;
- vector.push(20);
- vector.push(50);
- vector.push(80);
- vector.push(90);
- vector.push(15);
- for(Vector::iterator i = vector.begin(); i <= vector.end(); ++i)
- {
- if ((*i) < 30){
- std::cout << "30" << " ";
- }
- else if (((*i)>=30)&&((*i)<=60)){
- std::cout << "40" << " ";
- }
- else std::cout << "60" <<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement