Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
linearArray.hpp
- Committer:
- UHSLMarcus
- Date:
- 2016-10-05
- Revision:
- 2:92576523c23e
- Parent:
- 1:49758f1e1317
- Child:
- 3:8e9f85814809
- Child:
- 9:68d882e457c5
File content as of revision 2:92576523c23e:
template <class type>
LinearArray<type>::LinearArray(int size): elem_count(0), array_size(size) {
array = new type[size];
}
template <class type>
LinearArray<type>::~LinearArray() {
delete[] array;
}
template <class type>
int LinearArray<type>::add(type item) {
int ret = -1;
if (hasSpace()) {
array[elem_count] = item;
ret = elem_count++;
}
return ret;
}
template <class type>
void LinearArray<type>::remove(int index) {
if (index < elem_count) {
for (int i = index; i < elem_count-1; i++) {
array[i] = array[i+1];
}
elem_count--;
}
}
template <class type>
int LinearArray<type>::size() {
return array_size;
}
template <class type>
int LinearArray<type>::elements() {
return elem_count;
}
template <class type>
bool LinearArray<type>::hasSpace() {
return elem_count < array_size;
}
template <class type>
type& LinearArray<type>::operator[](int index) {
if (index < elem_count) {
return array[index];
}
return;
}