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:
- 5:0f65cdadb1a4
- Parent:
- 4:7743528fb9e5
- Child:
- 6:314f180362cb
--- a/linearArray.hpp Thu Mar 02 13:10:56 2017 +0000
+++ b/linearArray.hpp Wed Mar 08 10:48:34 2017 +0000
@@ -1,21 +1,21 @@
template<class type>
-LinearArray<type>::LinearArray(int size) :
- elem_count(0), array_size(size), front(0), rear(-1) {
- array = new type[size];
+LinearArray<type>::LinearArray(int size, bool forced) :
+ _elem_count(0), _array_size(size), _front(0), _rear(-1), _forced(forced) {
+ _array = new type[size];
}
template<class type>
LinearArray<type>::~LinearArray() {
- delete[] array;
+ delete[] _array;
}
template<class type>
int LinearArray<type>::push(type item) {
int ret = -1;
- if (elem_count < array_size) {
- if (rear == array_size - 1) rear = -1;
- array[++rear] = item;
+ if (elem_count < _array_size) {
+ if (_rear == _array_size - 1) _rear = -1;
+ _array[++_rear] = item;
ret = elem_count++;
}
@@ -28,8 +28,8 @@
type item = NULL;
if (elem_count > 0) {
- item = array[front++];
- if (front == array_size) front = 0;
+ item = _array[_front++];
+ if (_front == _array_size) _front = 0;
elem_count--;
}
@@ -38,12 +38,40 @@
}
template<class type>
+type& LinearArray<type>::pop() {
+
+ type item = NULL;
+
+ if (elem_count > 0) {
+ item = _array[_front++];
+ if (_front == _array_size) _front = 0;
+ elem_count--;
+ }
+
+ return item;
+
+}
+
+template<class type>
+type LinearArray<type>::peek() {
+
+ type item = NULL;
+
+ if (_front <= _rear) {
+ item = _array[_front];
+ }
+
+ return item;
+
+}
+
+template<class type>
type& LinearArray<type>::peek() {
type item = NULL;
- if (front <= rear) {
- item = array[front];
+ if (_front <= _rear) {
+ item = _array[_front];
}
return item;
@@ -52,7 +80,7 @@
template<class type>
int LinearArray<type>::size() {
- return array_size;
+ return _array_size;
}
template<class type>
@@ -62,5 +90,5 @@
template<class type>
bool LinearArray<type>::full() {
- return elem_count == array_size;
+ return elem_count == _array_size;
}