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.
Diff: linearArray.hpp
- Revision:
- 1:49758f1e1317
- Child:
- 2:92576523c23e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/linearArray.hpp Tue Oct 04 13:38:07 2016 +0000
@@ -0,0 +1,58 @@
+
+
+template <class type>
+LinearArray<type>::LinearArray(int size): elem_count(0) {
+ 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 sizeof(array);
+}
+
+template <class type>
+int LinearArray<type>::elements() {
+ return elem_count;
+}
+
+template <class type>
+bool LinearArray<type>::hasSpace() {
+ return elem_count < sizeof(array);
+}
+
+template <class type>
+type& LinearArray<type>::operator[](int index) {
+ if (index < elem_count) {
+ return array[index];
+ }
+ return;
+}