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:
- 2017-03-02
- Revision:
- 4:7743528fb9e5
- Parent:
- 3:8e9f85814809
- Child:
- 5:0f65cdadb1a4
File content as of revision 4:7743528fb9e5:
template<class type>
LinearArray<type>::LinearArray(int size) :
elem_count(0), array_size(size), front(0), rear(-1) {
array = new type[size];
}
template<class type>
LinearArray<type>::~LinearArray() {
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;
ret = elem_count++;
}
return ret;
}
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>
int LinearArray<type>::size() {
return array_size;
}
template<class type>
int LinearArray<type>::count() {
return elem_count;
}
template<class type>
bool LinearArray<type>::full() {
return elem_count == array_size;
}