-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Base.cpp
More file actions
149 lines (112 loc) · 2.48 KB
/
Array_Base.cpp
File metadata and controls
149 lines (112 loc) · 2.48 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Honor Pledge: ashstrin
//
// I pledge that I have neither given nor receieved any help
//on this assignment.
#include "Array_Base.h"
#include <stdexcept>
#include <iostream>
template <typename T>
Array_Base<T>::Array_Base (void) : cur_size_(0), max_size_(0), data_()
{}
template <typename T>
Array_Base<T>::Array_Base (size_t length) : cur_size_(length), max_size_(length), data_(new T[length])
{}
template <typename T>
Array_Base<T>::Array_Base (size_t length, T fill) : cur_size_(length), max_size_(length), data_(new T[length])
{
for(int i = 0; i < length; i++){
data_[i] = fill;
}
}
template <typename T>
Array_Base<T>::Array_Base (const Array_Base & arr) : cur_size_(arr.size()), max_size_(arr.max_size()), data_(arr.data_)
{
}
template <typename T>
Array_Base<T>::~Array_Base (void)
{
delete [] data_;
}
template <typename T>
const Array_Base<T> & Array_Base<T>::operator = (const Array_Base & rhs)
{
}
template <typename T>
T & Array_Base<T>::operator [] (size_t index)
{
}
template <typename T>
const T & Array_Base<T>::operator [] (size_t index) const
{
}
template <typename T>
T Array_Base<T>::get (size_t index) const
{
if(index <= cur_size_){
return data_[index];
}else{
throw std::out_of_range("Out of range");
}
}
template <typename T>
void Array_Base<T>::set (size_t index, T value)
{
if(index <= (cur_size_ - 1)){
data_[index] = value;
}else{
throw std::out_of_range("Out of range");
}
}
template <typename T>
int Array_Base<T>::find (T value) const
{
for(int i = 0; i < cur_size_; i++){
if(data_[i] == value){
return i;
}
}
return -1;
}
template <typename T>
int Array_Base<T>::find (T value, size_t start) const
{
if(start >= 0 && start <= cur_size_){
for(int i = start; i < cur_size_; i++){
if(data_[i] == value){
return i;
}
}
return -1;
}else{
throw std::out_of_range("Out of range");
}
}
template <typename T>
bool Array_Base<T>::operator == (const Array_Base & rhs) const
{}
template <typename T>
bool Array_Base<T>::operator != (const Array_Base & rhs) const
{}
template <typename T>
void Array_Base<T>::fill (T value)
{
for(int i = 0; i < cur_size_; i++){
data_[i] = value;
}
}
template <typename T>
void Array_Base<T>::reverse (void)
{
int lengthIndex = cur_size_ - 1;
int arrayHalf = cur_size_ / 2;
for(int i = 0, j = lengthIndex; i < j; i++, j--){
swap(i, j);
}
}
template <typename T>
void Array_Base<T>::swap (int index1, int index2)
{
T temp = data_[index1];
data_[index1] = data_[index2];
data_[index2] = temp;
}