Mozzi  version v2.0
sound synthesis library for Arduino
Stack.h
1 /*
2  * Stack.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2013-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
17 template <class T, int NUM_ITEMS>
18 class Stack
19 {
20 private:
21  T _array[NUM_ITEMS];
22  int top;
23 
24 public:
27  Stack(): top(-1)
28  {
29  }
30 
34  void push(T item)
35  {
36  if (top< (NUM_ITEMS-1)){
37  top++;
38  _array[top]=item;
39  }
40  }
41 
45  T pop()
46  {
47  if(top==-1) return -1;
48  T item =_array[top];
49  top--;
50  return item;
51  }
52 
53 };
A simple stack, used internally for keeping track of analog input channels as they are read.
Definition: Stack.h:19
Stack()
Constructor.
Definition: Stack.h:27
void push(T item)
Put an item on the stack.
Definition: Stack.h:34
T pop()
Get the item on top of the stack.
Definition: Stack.h:45