This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector.cpp
97 lines (76 loc) · 1.61 KB
/
Vector.cpp
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
/*#include "Vector.h"
template<typename T>
inline Vector::Vector<T>::Vector() {
vec = new T[1];
capasity = 1;
size = 0;
}
template <typename T>
inline Vector::Vector<T>::~Vector() {
delete[] vec;
}
template<typename T>
void Vector::Vector<T>::puhsBack(T data) {
if (size == capasity) {
T* temp = new T[capasity * growthFactor];
for (size_t i{}; i < size; i++) {
temp[i] = vec[i];
}
delete[] vec;
capasity *= growthFactor;
vec = temp;
}
vec[size] = data;
size++;
}
template<typename T>
T Vector::Vector<T>::getDataByIndex(size_t index) {
if (index < size)
return vec[index];
return -1;
}
template<typename T>
size_t Vector::Vector<T>::getSize() {
return size;
}
template<typename T>
size_t Vector::Vector<T>::getCapasity() {
return capasity;
}
template<typename T>
void Vector::Vector<T>::print() {
for (size_t i{}; i < size; i++) {
std::cout << vec[i] << ' ';
}
std::cout << std::endl;
}
*/
//template<typename T>
//Vector::Vector<T>::Vector(T* vec, const size_t& size, const size_t& capasity, const size_t& growthFactor)
// : vec(vec), size(size), capasity(capasity), growthFactor(growthFactor)
//{
//}
/*
#pragma once
#include<iostream>
namespace Vector {
template <typename T>
class Vector
{
T* vec;
size_t size;
size_t capasity;
size_t growthFactor = 2;
public:
Vector(T* vec, const size_t& size, const size_t& capasity, const size_t& growthFactor)
: vec(vec), size(size), capasity(capasity), growthFactor(growthFactor);
Vector();
~Vector();
void puhsBack(T data);
void getDataByIndex(size_t index);
size_t getSize();
size_t getCapasity();
void print();
};
}
*/