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.
Fork of Boboobooov4 by
Stack.cpp
00001 /* 00002 * mbed library for Stack 00003 * Copyright (c) 2011 Hiroshi Suga 00004 * Released under the MIT License: http://mbed.org/license/mit 00005 */ 00006 00007 /** @file Stack.cpp 00008 * @brief Stack 00009 */ 00010 00011 #include "Stack.h" 00012 00013 template <class T> 00014 Stack<T>::Stack (int p_size) { 00015 size = p_size + 1; 00016 buf = new T[size]; 00017 // buf = (T*)malloc(sizeof(T) * size); 00018 addr = 0; 00019 } 00020 00021 template <class T> 00022 Stack<T>::~Stack () { 00023 delete [] buf; 00024 // free(buf); 00025 } 00026 00027 template <class T> 00028 int Stack<T>::push (T dat) { 00029 00030 if (addr >= size) { 00031 return -1; 00032 } 00033 buf[addr] = dat; 00034 addr ++; 00035 return dat; 00036 } 00037 00038 template <class T> 00039 int Stack<T>::pop (T *dat) { 00040 00041 if (addr == 0) { 00042 return -1; 00043 } 00044 addr --; 00045 *dat = buf[addr]; 00046 return 0; 00047 } 00048 00049 template <class T> 00050 int Stack<T>::read (T *dat) { 00051 00052 if (addr == 0) { 00053 return -1; 00054 } 00055 *dat = buf[addr]; 00056 return 0; 00057 } 00058 00059 template <class T> 00060 int Stack<T>::available () { 00061 return size - addr; 00062 } 00063 00064 template <class T> 00065 int Stack<T>::use () { 00066 return addr; 00067 } 00068 00069 template <class T> 00070 void Stack<T>::clear () { 00071 addr = 0; 00072 } 00073 00074 template class Stack<int>; 00075 template class Stack<float>;
Generated on Thu Jul 14 2022 03:30:21 by
1.7.2
