vector.h
1.09 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
#ifndef __VECTOR_H__
#define __VECTOR_H__
class vector
{
int *dane;
unsigned int size;
public:
vector (int s)
{
dane = new int[s];
size = s;
for (unsigned i = 0; i < size; i++)
dane[i] = 0;
}
~vector ()
{
delete [] dane;
}
int& operator[] (unsigned int pos)
{
if (pos >= size)
abort ();
return dane[pos];
}
int operator[] (unsigned int pos) const
{
if (pos >= size)
abort ();
return dane[pos];
}
vector (const vector & s)
{
dane = new int[s.size];
size = s.size;
for (unsigned i = 0; i < size; i++)
dane[i] = s.dane[i];
}
vector & operator= (const vector & s)
{
if (this == &s)
return *this;
delete [] dane;
dane = new int[s.size];
size = s.size;
for (unsigned i = 0; i < size; i++)
dane[i] = s.dane[i];
return *this;
}
friend ostream & operator<< (ostream & o, const vector & v)
{
o << '[';
for (unsigned i = 0; i < v.size;i++)
{
o << v[i];
if (i != v.size - 1)
o << ',';
};
o << ']';
return o;
}
};
#endif /* __VECTOR_H__ */