-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvector.hpp
More file actions
114 lines (88 loc) · 2.96 KB
/
vector.hpp
File metadata and controls
114 lines (88 loc) · 2.96 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef VECTOR_HPP
#define VECTOR_HPP
#include "Errors.h"
#include <iostream>
using std::istream;
using std::ostream;
class ArrayBase {
public:
ArrayBase () { }
virtual ~ArrayBase () { }
int getsize() const {
return _size;
}
protected:
int _size;
static const int DefaultSize = 20;
};
template <typename T>
class ArrayT : public ArrayBase {
public:
// онструкторы
ArrayT ( int n = DefaultSize );
ArrayT ( const T*, int sz );
ArrayT ( const ArrayT<T>& );
// ƒеструктор
~ArrayT ( );
// опирование массива
ArrayT<T>& operator= ( const ArrayT<T>& );
// ѕерегрузка операторов сравнени€
bool operator == ( const ArrayT<T>& ) const;
bool operator != ( const ArrayT<T>& ) const;
static bool is_equal ( const ArrayT<T>&, const ArrayT<T>& );
// ќбъединение массивов
static ArrayT<T>& concat( const ArrayT<T>&, const ArrayT<T>&);
// ”меньшение длины массива
static ArrayT<T>& split_array ( const ArrayT<T>&, int pos, int num );
// ѕрибавление одного и того же числа ко всем элементам массива
ArrayT<T>& operator += ( const T& );
ArrayT<T>& add_value ( const T& );
ArrayT<T>& operator -= ( const T& );
ArrayT<T>& subst_value ( const T& );
// ”множение всех элементов массива на одно и то же число
ArrayT<T>& operator *= ( const T& );
ArrayT<T>& operator /= ( const T& );
ArrayT<T>& mult_value ( const T& );
ArrayT<T>& div_value ( const T& );
// —ложение массивов
ArrayT<T>& operator += ( const ArrayT<T>& );
ArrayT<T>& add_array ( const ArrayT<T>& );
// ¬ычитание массивов
ArrayT<T>& operator -= ( const ArrayT<T>& );
ArrayT<T>& subst_array ( const ArrayT<T>& );
// —ортировка массива
void QuickSortArr ( );
void QuickSortArr ( int st, int en );
// ѕерегрузка оператора []
T& operator [] ( int n ) {
if (n<_size)
return _arr[n];
else
throw RangeError(1);
};
const T& operator [] ( int n ) const {
if (n<_size)
return _arr[n];
else
throw RangeError(1);
};
// ѕоиск элементов в массиве
T arr_min( int& );
T arr_max( int& );
int FindEl( T );
// ќбмен
void arr_swap( int, int );
// ѕерегрузка потоков ввода-вывода
template <typename V>
friend istream& operator >> ( istream&, ArrayT<V>& );
template <typename V>
friend ostream& operator << ( ostream&, ArrayT<V>& );
private:
T* _arr;
void arr_resize( int );
};
template <typename T>
istream& operator >> ( istream&, ArrayT<T>& );
template <typename T>
ostream& operator << ( ostream&, ArrayT<T>& );
#endif // VECTOR_HPP