Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IndexError {};
- class Vector {
- int capacity_;
- int size_;
- int *buffer_;
- public:
- Vector (int capacity=10): capacity_(capacity), size_(capacity) {
- buffer_ = new int[capacity];
- }
- ~Vector () {
- delete [] buffer_;
- }
- int size() const {
- return size_;
- }
- bool empty() const {
- return size_ == 0;
- }
- int &index(n) const {
- if (n < 0 || n > size_)
- throw IndexError();
- return buffer_[n];
- }
- int &operator [](int n) {
- return index(n);
- }
- const int &operator [](int n) const {
- return index(n);
- }
- void clear() {
- size_ = 0;
- }
- int capacity() const {
- return capacity_;
- }
- int &front() {
- if (empty())
- throw IndexError();
- return buffer_[0];
- }
- const int &front() const {
- return front();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement