-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVector.h
More file actions
44 lines (40 loc) · 1.22 KB
/
Vector.h
File metadata and controls
44 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by dagor on 11/8/2022.
//
#ifndef VECTOR_H
#define VECTOR_H
#include <string>
#include <ostream>
const size_t INITIAL_CAPACITY = 10;
const std::string OUT_OF_RANGE_MESSAGE = "Index provided is out of range";
template <class T>
class Vector{
public:
// constructors and destructor
Vector(size_t size = INITIAL_CAPACITY){}
Vector(Vector<T>& other){}
~Vector() {}
// data access
const T& operator[] (size_t index) const;
T& operator[] (size_t index);
const T& at(size_t index) const;
T& at(size_t index);
// state functions
bool empty() const;
size_t size() const;
void resize(size_t new_size);
std::string toString() const;
friend std::ostream & operator<< (std::ostream & os, Vector<T> & obj); // optional. You may find it handy for testing purposes.
// adding data
void push_back(const T& value);
void insert(size_t index, const T& value);
// removing data
void pop_back();
void erase(size_t index);
// bulk change methods
void swap(Vector<T>& other);
Vector<T>& operator= (const Vector<T>& other);
// comparison operators
bool operator== (const Vector<T>& other);
};
#endif //VECTOR_H